1

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 Answers1

0

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

marmor
  • 27,641
  • 11
  • 107
  • 150
  • Thanks for your reply, really helped in getting caller number. I used onCallStateChanged(int state, String incomingNumber) but I am unable to get the number/contact for outgoing calls now. Can you help me with that? – Farhan Ahmed Nov 29 '18 at 05:44
  • see this: https://stackoverflow.com/questions/6611197/how-to-find-outgoing-number-in-telephony-manager – marmor Nov 29 '18 at 09:12
  • 1
    @Override public void onReceive(final Context context, Intent intent) { CallActivity.number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); } This is what I did and finally I am getting the number. Thanks marmor – Farhan Ahmed Nov 29 '18 at 11:25