Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read numbers from the PHONE_STATE intent action android 9 Not working

I was trying to retrieve the phone number from intent extra through onrecieve() method for the following broadcast receiver registered in manifest file.

  <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>

I can successfully able to read the phone number for all the version except android pie upgraded in my pixel 2 device. According to the documentation, app requires additional permission for reading phone number which are READ_CALL_LOG permission and the READ_PHONE_STATE permission but even after allowing these permission I still get missing permission for READ_CALL_LOG therefore I couldn't able to read the phone number. Please help me in resolving this issue.

like image 302
android dev Avatar asked Aug 08 '18 05:08

android dev


1 Answers

Make sure you grant READ_PHONE_STATE and READ_CALL_LOG permissions at runtime in Android 6.0+:
https://developer.android.com/distribute/best-practices/develop/runtime-permissions

Also, note that after granting these two permissions, you will receive ACTION_PHONE_STATE_CHANGED broadcast intent action twice; one with the EXTRA_INCOMING_NUMBER populated with the phone number, and another with it blank.

You can find more information here:
https://developer.android.com/reference/android/telephony/TelephonyManager.html#ACTION_PHONE_STATE_CHANGED

like image 185
SDev Avatar answered Sep 21 '22 15:09

SDev