I am using the Broadcast receiver to detect the incoming call and then call my custom incoming Screen as follow:
public class CallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
String msg = phoneNumber + " Incoming Call";
String name = "Gil Pires";
//showToast(context, msg);
Intent callerIntent = new Intent(context, CallerInfoActivity.class);
callerIntent.putExtras(callerIntent);
callerIntent.putExtra("EXTRA_PHONE_CALLER", phoneNumber);
callerIntent.putExtra("EXTRA_NAME_CALLER", name);
context.startActivity(callerIntent);
//showToast(context,msg);
}
}
void showToast(Context context,String message){
Toast toast=Toast.makeText(context,message,Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
}
}
And this is the CallScreeningService:
@RequiresApi(api = Build.VERSION_CODES.N)
public class CallService extends CallScreeningService {
@Override
public void onScreenCall(@NonNull Call.Details callDetails) {
CallResponse.Builder response = new CallResponse.Builder();
Uri callerPhone = callDetails.getHandle();
Log.e("CallBouncer", "Call screening service triggered " + callerPhone);
respondToCall(callDetails, response.build() );
}
}
So I'm not sure where is this CallScreeningService is beeing used as with the BroadcastReceiver I'm able to create and display my custom Screen on Incoming Calls?
I used CallScreenService to show a small window with caller details on incoming calls. You have to follow some steps to implement CallScreenService: First Declaration in Manifest.xml
Create a Class where you will implement CallScreenService and write your logic there myServiceClass:
}
You have to make your app default dialler app or default for caller id and spam
Now in your mainActivity request to change the default dialer app
activityResultLauncher: