Reputation: 152294
I am initiating call using Notification
's action:
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:+48123456"));
PendingIntent pCallIntent = PendingIntent.getActivity(context, 0, callIntent, 0);
Notification notification = new Notification.Builder(context)
.addAction(android.R.drawable.ic_menu_call, "Call", pCallIntent)
.build();
notificationManager.notify(0, notification);
After triggering Call
button I get following SecurityException
:
05-06 20:00:09.275 3426-6293/system_process W/ActivityManager﹕ Unable to send startActivity intent
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxxxx flg=0x10000000 cmp=com.android.phone/.OutgoingCallBroadcaster bnds=[128,231][423,327] } from null (pid=-1, uid=10142) requires android.permission.CALL_PHONE
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1191)
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:746)
at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3391)
at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:252)
at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:3272)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:237)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2146)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
I have set proper permissions in AndroidManifest
:
<uses-permission android:name="android.permission.CALL_PHONE" />
What should I do to fix it ?
Upvotes: 1
Views: 4188
Reputation: 1007544
A PendingIntent
is supposed to include the "security context" in which it was created, so I am a bit surprised that this isn't working, though I have certainly never tried to call a phone number from a Notification
.
Your likely options are:
Switch to DIAL_PHONE
, as that does not need a permission.
Have your PendingIntent
route to a BroadcastReceiver
of yours, which turns around and calls the phone number. Make sure that this is a non-exported BroadcastReceiver
(i.e., no <intent-filter>
), so other apps do not send you the broadcast, causing you to call the number at possibly inopportune moments.
Upvotes: 2