Unable to get phoneNumber from BroadcastReceiver even if BroadcastReceiver receiving all incomingnumber

100 views Asked by At

I placed below code in BroadcastReceiver and this code trigger every time when a new call arrives. But bundle not contains incoming_number. By printing out the bundle I get Bundle[{state=RINGING}] as output. and I only get this problem in new phones(>= Android 9.0)

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

There are 1 answers

0
David Wasser On

Documentation indicates that EXTRA_INCOMING_NUMBER is only populated if your app has the following permissions:

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.