Can we get Call details like caller number and contact details from InCallService or Telecom.Call?

1.7k Views Asked by At

I actually want to overlay default calling screen and handle everything on my activity. The problem I am facing is how can I get the caller number and if it is a contact stored in my phone from Telecom.Call object because that is the only available object in InCallService onCallAdded Method.

Thanks for your help in advance.

public MyConnectionService() {
}

@Override
public void onCallAdded(Call call) {
    super.onCallAdded(call);
    Log.d("Call","new call Added");
    CallActivity.call=call;
    startActivity(new Intent(this,CallActivity.class));
}

@Override
public void onCallRemoved(Call call) {
    super.onCallRemoved(call);
    Log.d("Call","Call Removed");
}

This is the activity to accept and reject calls. right now the screen show only 2 buttons to accept and reject the call and it is working fine, I need the contact details to show then on the screen as well.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call);

    name=findViewById(R.id.name);

    screenLock = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(
            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
    screenLock.acquire();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    name.setText(call.getRemainingPostDialSequence());  //call.getDetails().getCallerDisplayName()

    call.registerCallback(new Call.Callback() {
        @Override
        public void onCallDestroyed(Call call) {
            super.onCallDestroyed(call);
            CallActivity.this.finish();
        }

        @Override
        public void onDetailsChanged(Call call, Call.Details details) {
            super.onDetailsChanged(call, details);
            Log.d("details",call.getRemainingPostDialSequence()+":"+details.getCallerDisplayName());
        }
    });

}
1

There are 1 best solutions below

3
On

You have two options.

  1. asking the user to make your app the default Phone app (basically your app will be the new InCallService / InCallUI that you'd need to implement), see: https://developer.android.com/reference/android/telecom/InCallService

  2. implementing a PhoneStateListener to detect to phone state changes (idle/ringing/offhook) and displaying your UI above the default InCallUI when appropriate, see: https://developer.android.com/reference/android/telephony/PhoneStateListener and Add PhoneStateListener