I have been using the following code in a BroadcastReceiver
to get
the caller ID of incoming calls:
@Override
public void onReceive(Context aContext, Intent aIntent) {
String action = aIntent.getAction();
if (action==null) return;
if (!action.equals("android.intent.action.PHONE_STATE")) return;
String curState = aIntent.getStringExtra(TelephonyManager.EXTRA_STATE);
if ((TelephonyManager.EXTRA_STATE_RINGING.equals(curState))
&&(TelephonyManager.EXTRA_STATE_IDLE.equals(oldState)))){
String incNumber = aIntent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
// do something here
}
oldState=curState;
}
Unfortunately this has stopped working in Android 9.0 (API 28)
. More specifically,
aIntent.getStringExtra(EXTRA_INCOMING_NUMBER)
always returns null. In android versions<=API 27
everything works correctly
I have also added the READ_PHONE_STATE
and READ_CALL_LOG
permissions in the manifest file.
Any ideas? Anybody else experiencing the same problem?
Thanks in advance for your help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…