here i have use roadcastReceiver to get the incoming mobile number all permission is granted and the state is also changed but still shows the incoming number as null
min sdk = 24
compilesdk = 34
package com.msdev.blueconnect;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
import java.util.Objects;
public class PhoneStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Objects.equals(intent.getAction(), TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
// Incoming call!
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.i("IncomingCallActivity", "Incoming: " + incomingNumber);
// Process incoming number (e.g., display toast)
Toast.makeText(context, "Incoming call from: " + incomingNumber, Toast.LENGTH_SHORT).show();
}
}
}
}
Help me to resolve this issue…..
Thank you in advance
I have tried by inner class method but still it shows the incoming number is null