I have an app that checks the phone number of an incoming call against a blacklist.
I have used the below code for several versions of Android to get the phone number of an incoming call, but when I test it against Android P, it behaves unexpectedly.
For readability, I have removed all null checks from the code below.
public class IncomingCallHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = bundle
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
}
}
}
On Android versions less than P, onReceive with state EXTRA_STATE_RINGING may be called several times during an incoming call, but phoneNumber always has the same value (the actual incoming phone number).
On Android P, onReceive is called twice during an incoming call. The first time phoneNumber=null, the second time it is the actual phone number.
Is this a bug? Is it supposed to be like this? Do you get the same in your apps?