Questions tagged [android-pendingintent]

An Android class that provides a description of an Intent and target action to perform with it

From the PendingIntent API:

A description of an Intent and target action to perform with it. Instances of this class are created with getActivity(Context, int, Intent, int), getActivities(Context, int, Intent[], int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent, int); the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time.

By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: often, for example, the base Intent you supply will have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.

Useful links

1881 questions
18
votes
2 answers

Create new Pending Intent every time in Android

How do I create a pending intent everytime? Currently my existing pending intent is getting replaced with a new one. I tried using FLAG_ONE_SHOT as well as CANCEL_CURRENT but it didn't work.
Chintan
  • 906
  • 4
  • 14
  • 30
18
votes
10 answers

Android Notification Action is not fired (PendingIntent)

I am trying to add an Notification action item in my app which is a music player. When a stream is started a notification should be triggered and an stop button for the stream should be displayed in the notfication. The notification working fine so…
17
votes
4 answers

Opening a PDF file using FileProvider uri opens a blank screen

I'm creating a PDF file on my app and writing it to the external storage, "Download" directory. Now, when I open it through my app with an intent action.VIEW using FileProvider uri, Google PDF Viewer displays a blank screen, Adobe Acrobat cannot…
17
votes
3 answers

Multiple calls to AlarmManager.setRepeating deliver the same Intent/PendingIntent extra values, but I supplied different ones

Solved while writing this question, but posting in case it helps anyone: I'm setting multiple alarms like this, with different values of id: AlarmManager alarms = (AlarmManager)context.getSystemService( Context.ALARM_SERVICE); Intent i = new…
Chris Boyle
  • 11,423
  • 7
  • 48
  • 63
16
votes
2 answers

Android: Start Service with Context.startService vs PendingIntent.getService

Context.startService Intent intent = new Intent(context, MyService.class); context.startService(intent); PendingIntent.getService Intent intent = new Intent(context, MyService.class); PendingIntent pi = PendingIntent.getService(context, 0, intent,…
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
16
votes
1 answer

passing intent extra to android broadcast receiver

I have created a AlarmReceiver class which is used as broadcast receiver for alarm. The issue is that I need to send some values from the class which is setting the alarm to the broadcast receiver class. setAlarmManager.java Intent i = new…
16
votes
1 answer

Stop the setrepeat of Android alarmmanager

I have created the alarm as shown below Intent intent = new Intent(this, Areceiver.class); PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0); AlarmManager am = (AlarmManager)…
sankara rao bhatta
  • 649
  • 5
  • 9
  • 13
16
votes
2 answers

FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT

My app sets a repeating alarm on user interaction, it might change the interval time set for the broadcast with Alarm Manager. There is not much in the way of extras. Is the update or cancel flag better in this case? Thanks
Dory
  • 7,462
  • 7
  • 33
  • 55
15
votes
8 answers

Full screen intent not starting the activity but do show a notification on android 10

I try to launch activity for a broadcastReceiver by using the next code Intent i = new Intent(context, AlarmNotification.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); if (Build.VERSION.SDK_INT >=…
14
votes
1 answer

In Android 12/API 31, Geofence doesn't work with IMMUTABLE pendingintent. Why?

A new PendingIntent field in PendingIntent is FLAG_IMMUTABLE. In 31, you must specify MUTABLE or IMMUTABLE, or you can't create the PendingIntent, (Of course we can't have defaults, that's for losers) as referenced here According to the (hilarious)…
Mathias
  • 3,879
  • 5
  • 36
  • 48
14
votes
2 answers

PendingIntent to launch and stop a Service

I'm trying to make a simple widget with a button that start a Service with the OnClickPendingIntent(). I can start it fine but I can't figure out a way to stop it (I know I can do it with a BroadcastReceiver or something similar but I would like to…
iGio90
  • 3,251
  • 7
  • 30
  • 43
14
votes
3 answers

Get details about Intent of a PendingIntent

I was wondering if it's possible to get some more info out of a PendingIntent that I haven't created myself. To be more precise: is it possible to somehow retrieve the original Intent of a PendingIntent? I don't need to execute it, but would like to…
Peterdk
  • 15,625
  • 20
  • 101
  • 140
13
votes
3 answers

AlarmManager, BroadcastReceiver and Service not working

I'm refactoring some code so that my app will pull data from a website once a day at a given time. From my research, it seems like AlarmManager is the most appropriate approach. The tutorial I have been following is:…
pyko
  • 3,399
  • 5
  • 26
  • 31
13
votes
5 answers

Notification opens activity, back button pressed, main activity is opened?

The best way I can describe my problem is like this: A notification is created at boot (with a BroadcastReceiver). My app main activity is opened and the home button is pressed (the app is still running in the background until the system closes…
13
votes
3 answers

Can't start activity from BroadcastReceiver on android 10

I updated my OS version to android 10 last night, and since then the startActivity function inside the broadcast receiver is doing nothing. This is how I try to start the activity based on the answer of CommonsWare: Intent i = new Intent(context,…