This is the code I used to do my work, but unfortunately It doesn't work for my device with Android Pie(9.0). But It works for device with Android Naugat(7.0). I already enabled the phone permission for the app using device App Settings. Can you give me a solution for this?
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if(extras!=null){
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
String phoneNo = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "You Got A Call From " + phoneNo, Toast.LENGTH_SHORT).show();
}
}
}
}