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
6
votes
1 answer

Android: How do I access an AsyncTask from a PendingIntent created by a status bar notification?

My application starts an AsyncTask which downloads a file from a URL. At the same time it creates a status bar Notification which tells the user the percentage complete of the download. I'm trying to make my application respond to clicking the…
6
votes
4 answers

AlarmManager triggers PendingIntent too soon

I've searched for 3 days now but didn't find a solution or similar problem/question anywhere else. Here is the deal: Trigger in 1 hour -> works correct Trigger in 2 hours -> Goes of in 1:23 Trigger in 1 day -> Goes of in ~11:00 So why is the…
Wezelkrozum
  • 831
  • 5
  • 15
6
votes
1 answer

What happens to PendingIntents when the app is removed?

As the title suggests, I'm interested to discover what Android does with PendingIntents created by an application which has been removed from a device. My research so far involves setting an alarm using AlarmManager and a pending intent. In the…
barry
  • 4,037
  • 6
  • 41
  • 68
5
votes
2 answers

Foreground Notification in Android starts new Activity (via pendingIntent) instead of existing one

I have a music stream app and I want to display a foreground notification when the music is streaming. I'm doing the streaming in a seperate service and the code I use for the foreground notification is the following: Notification notification = new…
5
votes
3 answers

Two buttons with PendingIntents - Widget

I'm creating a widget with two buttons. One of them updates the content of the widget and the second one must launch an activity. I have two PendingIntent for each action, but I can't make them both work. If one works the other one doesn't. I've…
5
votes
1 answer

What is the concept of Pending Intent? Why and when we use Pending Intent?

My question is simple. What is the concept of Pending Intent? Why and when we use Pending Intents? Please also give code example if possible
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
5
votes
1 answer

Android: Opening wrong Activity from the widget

I have been struggling with this problem for a while now. I have a widget which displays summary of a cooking recipe. The widget is clickable so whenever user clicks on it the new activity is opened with a full description of that recipe. The…
Marqs
  • 17,800
  • 4
  • 30
  • 40
5
votes
1 answer

How to restart android app programmatically

I want to re-start my app through Pending intent. Below code is not working. val intent = Intent(this, Activity::class.java).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP } val pendingIntentId = 1 val pendingIntent =…
Srihari
  • 2,387
  • 9
  • 51
  • 82
5
votes
1 answer

How do I schedule a notification in Android 13?

Previous questions on Stack Overflow do not account for Android 13's new permission model, hence I am opening a new question. My app currently uses an AlarmManager to set a notification for a user at a pre-defined point in the future. Think of this…
5
votes
1 answer

Targeting S+ (version 33 ) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified

App crashes at runtime with the following error : Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if…
5
votes
1 answer

How can I send an SMS from a BroadcastReceiver and check its status?

So this is my BroadcastReceiver public class IncomingSMSListener extends BroadcastReceiver { private static final String SMS_EXTRA_NAME = "pdus"; @Override public void onReceive(Context context, Intent intent) { SmsMessage[] messages =…
AxiomaticNexus
  • 6,190
  • 3
  • 41
  • 61
5
votes
1 answer

AlarmManager does not work when the app is closed. Why is that?

Good day, I've built a timer into my Android app that sends a message after a certain time. To do this, I added an AlarmManager with a pending intent. Everything works as it should when I have the app open. It also works in the lock screen. But when…
5
votes
3 answers

PendingIntent.getBroadcast not working in Oreo

I have an app already on playstore long time ago, recently the notifications is not open with users this is my code private void showNotification () { PhoneUtils.clearAllNotifications(getApplicationContext()); NotificationManager…
Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175
5
votes
2 answers

Pending Intent does not launch Activity if app is already open or in background

In my app, i have a widget. If user clicks on widget, I am opening SplashScreen using pending intent using below code. PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); …
5
votes
3 answers

Cant get Extras from intent when application is in background

I try to execute a function in my MainActivity when a notification is clicked. The function needs a data that I put in intent extras. The problem is when I click the notification when the application is running the function is executed, but when I…