简体   繁体   English

即使 BroadcastReceiver 收到所有传入号码,也无法从 BroadcastReceiver 获取电话号码

[英]Unable to get phoneNumber from BroadcastReceiver even if BroadcastReceiver receiving all incomingnumber

I placed below code in BroadcastReceiver and this code trigger every time when a new call arrives.我将下面的代码放在 BroadcastReceiver 中,每次新呼叫到达时都会触发此代码。 But bundle not contains incoming_number.但捆绑不包含incoming_number。 By printing out the bundle I get Bundle[{state=RINGING}] as output.通过打印包,我得到Bundle[{state=RIN​​GING}]作为输出。 and I only get this problem in new phones(>= Android 9.0)我只在新手机中遇到这个问题(>= Android 9.0)

Bundle bundle = intent.getExtras();
System.out.println("Kokp 1:- " + bundle);
String phoneNumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

Documentation indicates that EXTRA_INCOMING_NUMBER is only populated if your app has the following permissions:文档表明,仅当您的应用具有以下权限时才会填充EXTRA_INCOMING_NUMBER

This extra is only populated for receivers of the ACTION_PHONE_STATE_CHANGED broadcast which have been granted the Manifest.permission.READ_CALL_LOG and Manifest.permission.READ_PHONE_STATE permissions.此额外内容仅针对已被授予 Manifest.permission.READ_CALL_LOG 和 Manifest.permission.READ_PHONE_STATE 权限的 ACTION_PHONE_STATE_CHANGED 广播的接收器填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM