我正在使用广播接收器来检测来电,然后调用我的自定义来电屏幕,如下所示:
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();
}
}
这是 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() );
}
}
所以我不确定这个 CallScreeningService 与 BroadcastReceiver 一起在哪里使用,我可以在来电时创建和显示我的自定义屏幕?