Getting the caller ID in Android 9

前端 未结 2 636
清歌不尽
清歌不尽 2020-12-09 04:53

I have been using the following code in a BroadcastReceiver to get the caller ID of incoming calls:

@Override
public void onReceive(Context aCo         


        
相关标签:
2条回答
  • 2020-12-09 05:22

    I found the answer to my question:

    First, in Android 9, you have to explicitly ask for both the READ_PHONE_STATE and the READ_CALL_LOG permissions at run time. In previous Android versions you only had to ask for the READ_PHONE_STATE permission. Both of them have to be asked at run time.

    Second, if both of the above permissions have been given, the onReceive method is called twice (!!). The first time the intent is "empty" (EXTRA_INCOMING_NUMBER is null). The second time the intent is normally populated as it should. This is documented in the TelephonyManager Documentation.

    0 讨论(0)
  • 2020-12-09 05:36

    Add READ_CALL_LOG permission in manifest as below :

    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    

    Then

    Apps -> Your App -> Permissions -> Grant Call Logs Permission

    Your should get phone number now, after the second time your receiver is called

    0 讨论(0)
提交回复
热议问题