Intent Action Call in Android 5

I have this code that works fine in Android 4.4 and previous:

Intent intent = new Intent(Intent.ACTION_CALL);         
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);

      

Now in Android 5.0 Lollipop this code doesn't work and shows this exception:

Fatal Exception: android.content.ActivityNotFoundException
No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxx pkg=com.android.phone }

      

In the documentation, this one Intent

doesn't look out of date:

Any idea? thanks in advance

+3


source to share


4 answers


It seems that the package name has been changed from

com.android.phone 

      

to



com.android.server.telecom.

      

Hope this helps!

+9


source


An alternative to using a hand-coded string is to use the default intent

as follows:

Intent out = new Intent(Intent.ACTION_CALL );
out.setData(Uri.parse("tel:" + Uri.encode("+12345#123")));
startActivity(out);

      



This will pass the intent to the system and all phone-enabled apps will respond instead of the specific one defined by the String action

+1


source


This means that you are trying to call com.android.phone

, but you are not. There are no miracles. It won't work. Either the package is named differently, or you are using a semi-element emulator, or so with missing material. Not to mention, you should always have it try/catch

around startActivity()

as there is no guarantee that it will succeed (especially when targeting external packages)

0


source


This worked for me on Android 4.4:

    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setPackage("com.android.dialer");
    intent.setData(Uri.parse("tel:1111111111"));
    startActivity(intent); 

      

If you are using Eclipse, open the dialer application and in DDMS, check the dialer package name; in my case it was "com.android.dialer".

-2


source







All Articles