0

Basically I'd like to start the current phone call ui from a button in one of my activities.

So far, I've been able to start a new call using

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:000000"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

or to move to the phonebook using:

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

I've also tried to use that code, but it seems not to be working on HTC devices and some Huawei (ri is null).

Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage("com.android.phone");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null) 
{
    Intent intent = new Intent(intentToResolve);
    intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

What I'd like to get is move directly to the call ui. The behaviour is the same as in this procedure:

  1. Be in a phone call
  2. Go back to the Home screen
  3. Expand the notification bar
  4. Click on the call row

I don't know how to achievve and how to make it works on all devices.

Thanks for your precious help.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Manitoba
  • 8,522
  • 11
  • 60
  • 122

1 Answers1

0

you have to do as suggested on this answer: android.permission.CALL_PHONE for tablets

add the call phone permission:

<uses-permission android:name="android.permission.CALL_PHONE"/>

and then call with Intent.ACTION_CALL.

Intent intentcall = new Intent(
          Intent.ACTION_CALL, 
          Uri.parse("tel:" + phonenumber));
startActivity(intentcall);

edit:

there's a way you could do, but it won't work in Lollipop and forward, as it's been deprecated due to security reasons.

You could use the ActivityManager to get the running tasks and then analyse the content of each RunningTaskInfo to determine which one is the "phone" and then use the task ID to call moveTaskToFront. It possibly work, but as I said, it will not work with Lollipop and future versions.

Community
  • 1
  • 1
Budius
  • 39,391
  • 16
  • 102
  • 144
  • 1
    The intention of the question is not to place a call, but to return to the in-call screen of one *already in progress*. Will this work for that? – Chris Stratton Mar 06 '15 at 16:19
  • oh... I'm very sorry, I understood it wrong. I will not work then. – Budius Mar 06 '15 at 16:39
  • take a look on my edit. Not a great answer, but just throwing some ideas. – Budius Mar 06 '15 at 16:52
  • Hello,it seems to work on old devices such as LG L5, but when I move to Samsung ACE 4 or S4, or event LG L65, I got an issue. Running `moveTaskToFront` on `com.android.phone id` doesn't work and throws a warning: `Task to front request from 10112 stopped`. Any idea why it doesn't work ? (Permissions look to be ok). – Manitoba Mar 09 '15 at 09:56
  • Sorry, i'm testing it on android `4.02` and `4.4.2`. No lollipop at all. – Manitoba Mar 09 '15 at 10:10
  • don't know then. That was a "best guess" approach. – Budius Mar 09 '15 at 10:11