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 Intent
doesn't appear deprecated:
Any idea? Thanks in advance
An alternative to using the action String manually encoded is to use the default
intent
like so:This will pass the intent to the system and all apps with phone capability will respond instead of the specific one determined via the action String
This means you are trying to call
com.android.phone
but it's not there. No miracles. It's not gonna work. Either the package is named differently or you are using semi-backed emulator or so with missing stuff. Not to mention you must always havetry/catch
aroundstartActivity()
as there's no guarantee it gonna success (especially when targeting external packages)This one worked for me on Android 4.4:
If using Eclipse, open the system dialer app and in DDMS, check for the name of the dialer package; in my case was "com.android.dialer".
Seems like the package name has been changed from
to
Hope this helps!