[英]How to get the number that is being dialed the , the outgoing number in android
I keep getting a value of null on the outgoing number I have tried a couple solutions from the web . 我在网上尝试了几种解决方案时,传出号码始终保持null值。
In my manifest I have these relevant lines 在我的清单中,我有这些相关内容
<uses-permission android:name="android.permission.READ_PHONE_STATE" ></uses-permission>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" > </uses-permission>
<receiver android:name=".home.OutgoingReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</action>
</intent-filter>
</receiver>
My receiver looks likes this , you will notice that I have been trying to retrieve the number in various ways here but I keep getting null value 我的接收器看起来像这样,您会注意到我一直在尝试以各种方式检索该数字,但我一直得到空值
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
final String originalNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER).toString();
Log.d("APP", "outgoing,ringing:" + originalNumber);
}
String ph = intent.getExtras().getString(OutgoingReceiver.INTENT_PHONE_NUMBER);
// savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
String phoneNumber = getResultData();
if (phoneNumber == null) {
// We could not find any previous data. Use the original phone number in this case.
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
String phoneNumberTest = intent.getExtras().getString(OutgoingReceiver.INTENT_PHONE_NUMBER);
First add this to your manifest: 首先将其添加到清单中:
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
Then add this to your receiver: 然后将其添加到您的接收器中:
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
String outoingNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.