0

I'm trying get incoming call number on android 11 API 30 in API 27 I used to do: AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<receiver android:name=".PhoneStateReceiver">
<intent-filter>
    <action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>

and the Broadcast receiver :

 @Override
public void onReceive(Context context, Intent intent) {
    try {
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
            Toast.makeText(context,"Incoming Number is: " + incomingNumber, Toast.LENGTH_SHORT).show();
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
  • You can find the answer follow to the next link: https://stackoverflow.com/questions/13154445/how-to-get-phone-number-from-an-incoming-call – Ivantsov Nick May 19 '22 at 18:51

0 Answers0