- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
几周以来我一直在研究这个问题。我正在制作一个应用程序,它会选择来电号码并在通话结束后将其显示在对话框中。在 android PIE 9.0 以下一切正常。该数字在 android PIE 中始终为 null。我已授予所有权限,包括 READ_CALL_LOGS
但同样的问题。来电号码为空。所以请任何人帮助我...
这是我的 list 文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.softixtechnologies.phonemanager">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/calllogo"
android:label="@string/app_name"
android:persistent="true"
android:roundIcon="@drawable/calllogo"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".activities.CallLogEntryActivity"></activity>
<activity android:name=".activities.CallLogsActivity" />
<activity android:name=".activities.IgnoredNumbersActivity" />
<activity android:name=".activities.IContactsActivity" />
<activity android:name=".activities.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.CategoryPhoneActivity" />
<activity
android:name=".activities.LogsActivity"
android:label="@string/title_activity_logs"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.CategoryActivity"
android:label="@string/title_activity_category"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".MainActivity" />
<receiver
android:name=".callhelpers.CallReciever"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>
这是我的代码:
public class PhoneCallReceiver extends BroadcastReceiver {
private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static Date callStartTime;
private static boolean isIncoming;
private static String savedNumber;
public String phoneNr ;
DatabaseHelper databaseHelper ;
@Override
public void onReceive(final Context context, Intent intent) {
databaseHelper = new DatabaseHelper(context);
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
} else {
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
int state = 0;
if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
state = TelephonyManager.CALL_STATE_IDLE;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
state = TelephonyManager.CALL_STATE_OFFHOOK;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = TelephonyManager.CALL_STATE_RINGING;
}
onCallStateChanged(context, state, number);
}
}
protected void onIncomingCallStarted(Context ctx, String number, Date start){}
protected void onOutgoingCallStarted(Context ctx, String number, Date start){}
protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end){}
protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end){}
protected void onMissedCall(final Context ctx, final String number, Date start){}
public void onCallStateChanged(Context context, int state, String number){
if (lastState == state) {
return;
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
isIncoming = true;
callStartTime = new Date();
savedNumber = number;
onIncomingCallStarted(context, number, callStartTime);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if (lastState != TelephonyManager.CALL_STATE_RINGING) {
isIncoming = false;
callStartTime = new Date();
onOutgoingCallStarted(context, savedNumber, callStartTime);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
onMissedCall(context, savedNumber, callStartTime);
} else if (isIncoming) {
onIncomingCallEnded(context, savedNumber, callStartTime, new Date());
} else {
onOutgoingCallEnded(context, savedNumber, callStartTime, new Date());
}
break;
}
lastState = state;
}
public boolean contactExists(Context context, String number) {
Uri lookupUri = Uri.withAppendedPath(
ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
String[] mPhoneNumberProjection = { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
return true;
}
} finally {
if (cur != null)
cur.close();
}
return false;
}
}
非常感谢您的帮助!!
最佳答案
有两种不同“类型”的电话状态接收器,具有 Manifest.permission.READ_CALL_LOG
权限的接收器和没有权限的接收器。
如果一个接收者没有Manifest.permission.READ_CALL_LOG
权限,它会被调用所有状态改变一次,没有EXTRA_INCOMING_NUMBER
额外。
如果接收器确实具有上述权限,就像您的情况一样,它会在每次状态更改时被调用两次,一次没有 EXTRA_INCOMING_NUMBER
权限,另一次有权限。
因为你有这个代码:
if (lastState == state) {
return;
}
在您的 onCallStateChanged
方法中,您基本上跳过了第二次调用,因此丢失了 EXTRA_INCOMING_NUMBER
信息。
如果您确定您拥有 READ_CALL_LOG
权限,您可以尝试完全跳过没有那个额外的重复的接收器调用(但是请注意,为那个额外的获得“空”值是有区别的这意味着一个私有(private)号码调用,并且根本没有得到额外的),就像这样:
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
if (!intent.getExtras().containsKey(TelephonyManager.EXTRA_INCOMING_NUMBER)) {
Log.i("Call receiver", "skipping intent=" + intent + ", extras=" + intent.getExtras() + " - no number was supplied");
return;
}
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
关于android - 在 android PIE 9 中结束通话后来电号码为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57441487/
这与 What is call/cc? 有关,但我不想为了自己的目的劫持这个问题,并且它的一些论点(例如与 setjmp/longjmp 的类比)回避了我。 我想我对什么是延续有足够的了解,我认为它是
我一直在浏览 Skype 开发 API,并想知道是否有一种方法可以让我知道 Skype 是否正在通过某些 API 运行事件调用。 Skype.Client.IsRunning 告诉 Skype 应用程
这个问题的两个小部分希望能为我消除一些歧义。 首先,调用WCF服务哪个更好? using (var myService = new ServiceClient("httpBinding")){
我在我的 Objective-C 应用程序中使用 CallKit。 我可以使用 CallKit 调用电话。如果有第二个电话打进来,我成功地将其设置为保持状态。当我结束第二个电话时, - (void)p
是否可以使用 java(JME 或 Android)捕获语音音频流,对其进行自定义加密,然后通过常规 GSM 调用将其作为常规流发送?当然,在其他手机上解密密码。是否允许应用程序级别的 java 拦截
我正在为 iOS 进行个人调整。我想在电话显示任何内容之前断开/连接电话。我连接到类 SBUIFullscreenAlertAdapter 的 initWithAlertController: 方法。
我对 callkit 有疑问(但不是真的)。 我在我的应用程序中实现了 callkit,它运行良好。我可以接到我的应用程序的第二个电话,callkit 为我提供了结束并接受、拒绝或保留并接受的选项。如
我一直在寻找在两个同伴之间进行实时语音(通话)的方法,但只找到了如何录制语音并发送它们或发送照片和文本。但我想要的是两个同伴能够互相打电话。那么,在 Android 上使用 WiFi P2P 管理器是
怎么了伙计们!好久没问过关于SO的问题了,感觉有点脱节,哈哈。无论如何,我最近使用 VOIP 发现了美妙的网络语音通话世界。和 WebRTC 我正在为我的一个想法进行一些研发,并且我基本上会喜欢以下问
我正在制作一个可以调用电话的应用程序,但我需要帮助才能在不显示拨号界面的情况下调用电话,例如,如果我按下按钮调用,它会调用电话但会停留在同一位置: 这是我的应用程序界面: 我不需要这个拨号界面,当按下
我是 Android 开发的新手(例如,我知道在 iOS 中这是不可能的)。 我知道,我需要打电话: Intent intent = new Intent(Intent.ACTION_CALL); i
注意:事实证明,原始问题的假设是不正确的。在底部查看有关其编辑的更多详细信息。 现在是关于节电模式,而不是节电模式和打盹模式。它也不是关于 Service&BroadcastReceiver,而只是
我正在开发一个机器人,您可以通过 Skype 向其发送消息和调用。该机器人在 Azure 函数中运行。我的消息部分正在工作。我已在 Azure 中将机器人配置为具有调用功能,并且我可以调用该机器人,但
在我的应用中,用户可以选择 call 联系人簿中的其他人。启动 call 应用程序很容易,但是我想知道的是,在 call 发生时我们是否可以播放简短的音乐文件,因此用户可以通过直接 call 他们的
我正在开发一个机器人,您可以通过 Skype 向其发送消息和调用。该机器人在 Azure 函数中运行。我的消息部分正在工作。我已在 Azure 中将机器人配置为具有调用功能,并且我可以调用该机器人,但
在这个问题的某些版本中,OP 会说“我如何在下午 5 点在我的应用程序中触发方法调用?” 然后人们会回答“你怎么知道你的应用会在下午 5 点打开”?这变成了另一个问题,原来的问题消失了。 所以让我们避
我想在单击按钮时发起 Skype 通话。我查找了几种可用的解决方案,但我猜大多数都已经过时并且无法正常工作。有人可以帮我解决这个问题吗?我是 Android 编程的新手。我已经包含在下面的代码中。任何
在 iOS 上,是否可以通过 URI 启动 Skype 语音通话,同时将我的应用程序保持在前台? 如果是这样,是否也可以通过启用扬声器的 URI 启动 Skype? (为什么?我正在尝试支持语音通信,
我在 Play 商店中有十几个应用程序,它们都是相同的,但针对不同的客户端进行了 UI 调整。我最近收到一封来自 Google Play 的自动电子邮件,内容涉及我的 2 个应用程序(但不是其他应用程
我想在 android 中进行 SIP 点对点 VoIP 调用。此调用应在本地网络中进行,无需访问互联网。事实上,我不想使用任何外部服务器来注册配置文件。但是我不知道在配置文件生成器的 serverD
我是一名优秀的程序员,十分优秀!