2

I have read everywhere that the use of a pendingIntent is to allow another application to obtain the required permissions to start an Intent that was instantiated inside another application's code. What permissions are these and how does using a pendingIntent help?

Quoting another answer on pendingIntents:

"A PendingIntent is a token that you give to a foreign application (e.g. NotificationManager, AlarmManager, Home Screen AppWidgetManager, or other 3rd party applications), which allows the foreign application to use your application's permissions to execute a predefined piece of code."

Felipe Calderon
  • 675
  • 2
  • 7
  • 17

1 Answers1

0

If we use PendingIntent, the application which uses the intent need not have that permission. But the application which creates PendingIntent must definitely have the required permission for Intents.

A very clear example is given in the link that I posted in the comment.

Application A have the permission to read the user's contacts but B does not. In that case if a privileged Application A gives Application B a pending intent so that B can send it when it wants to read a contact data. It is the responsibility of A to ask the user which contact data the user wants to give to B, and only give B that data. It is the responsibility of the user to decide whether application B is trustworthy for the contact data the user selected.

Community
  • 1
  • 1
Antrromet
  • 15,294
  • 10
  • 60
  • 75
  • What about when an application needs to start an activity of another application? Therefore a pendingIntent is created to start the activity belonging to another application. In this case, which permissions are needed? – Felipe Calderon Aug 11 '15 at 07:15
  • To start an activity of some other application, you need not have any special permissions. – Antrromet Aug 11 '15 at 07:17
  • When using notifications, we do. For example here: Intent intent = new Intent(this,MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); – Felipe Calderon Aug 11 '15 at 07:21
  • the Intent "intent" must be sent when clicking on a notification. – Felipe Calderon Aug 11 '15 at 07:24
  • In the above example you've not specified any permission at all. You are using http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int) version of creating a PendingIntent and all you specified is the context, requestcode, intent and flags. There is no permission whatsoever. – Antrromet Aug 11 '15 at 07:24
  • why do I need a pendingIntent for notifications then, like in this case? – Felipe Calderon Aug 11 '15 at 07:26
  • You use PendingIntents with Notifications because you're launching the activity only when the user clicks on the notification. You're delaying the launching of the intent based upon when the user clicks on the notification. – Antrromet Aug 11 '15 at 07:28
  • So permissions are not used in this case? Thank you btw – Felipe Calderon Aug 11 '15 at 07:41