PendingIntent is not working on Android O

Never use an implicit Intent when an explicit Intent will do. Android O helps enforce this by banning the receipt of implicit Intent broadcasts from manifest-registered receivers. Step #1: Remove the <intent-filter> from your <receiver> (which also means that you could get rid of android:exported=”false”, as that is now the default value) Step #2: Replace … Read more

Cancelling a PendingIntent

Where you want to cancel it, you would do the following (somewhere else in your code base): PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT).cancel(); where intent is the same one as referenced in your code above. PendingIntent.getBroadcast(…) using the PendingIntent.FLAG_UPDATE_CURRENT will return a reference to the existing one already created, or create one if it doesn’t currently exist.

Multiple notifications to the same activity

If the PendingIntent has the same operation, action, data, categories, components, and flags it will be replaced. Depending on the situation i usually solve this by providing a unique request code either as static values (0,1,2) or the row id of the data I’m receiving from the DB. PendingIntent.getActivity(context, MY_UNIQUE_VALUE , notificationIntent, PendingIntent.FLAG_ONE_SHOT); Then I … Read more

Notification passes old Intent Extras

You are sending the same request code for your pending intens. Change this: PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); To: PendingIntent contentIntent = PendingIntent.getActivity(context, UNIQUE_INT_PER_CALL, notificationIntent, 0); intents are not created if you send the same params. They are reused.

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified

If using java or react-native then paste this inside app/build.gradle dependencies { // … implementation ‘androidx.work:work-runtime:2.7.1’ } If using Kotlin then use this dependencies { // … implementation ‘androidx.work:work-runtime-ktx:2.7.0’ } and if anybody still facing the crash issue for android 12 then make sure you add following in AndroidMenifest.xml <activity … android:exported=”true” // in most … Read more

How to resolve “Missing PendingIntent mutability flag” lint warning in android api 30+?

You can set your pending intent as val updatedPendingIntent = PendingIntent.getActivity( applicationContext, NOTIFICATION_REQUEST_CODE, updatedIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag ) According to the docs here: https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies … Read more

How to use “goAsync” for broadcastReceiver?

You can find short explanation here. Use goAsync() if you want to handoff the processing inside of your BroadcastReceiver‘s onReceive() method to another thread. The onReceive() method can then be finished there. The PendingResult is passed to the new thread and you have to call PendingResult.finish() to actually inform the system that this receiver can … Read more

Is it possible to create multiple PendingIntents with the same requestCode and different extras?

Actually, you don’t “create” PendingIntents. You request them from the Android framework. When you request a PendingIntent from the Android framework, it checks to see if there is already a PendingIntent that matches the criteria you pass as arguments. If so, it does not create a new PendingIntent, it just gives you back a “token” … Read more

Get list of active PendingIntents in AlarmManager

adb shell dumpsys alarm > dump.txt dump.txt: Current Alarm Manager state: Realtime wakeup (now=1309361618777): RTC_WAKEUP #5: Alarm{4822f618 type 0 com.google.android.gsf} type=0 when=1309882326582 repeatInterval=522747000 count=0 operation=PendingIntent{47dd3740: PendingIntentRecord{4822aeb8 com.google.android.gsf broadcastIntent}} … RTC #5: Alarm{4810f9d8 type 1 com.tmobile.selfhelp} type=1 when=1309445979715 repeatInterval=86400000 count=1 operation=PendingIntent{4815a5c8: PendingIntentRecord{4810f960 com.tmobile.selfhelp startService}} RTC #4: Alarm{4810f668 type 1 com.tmobile.selfhelp} type=1 when=1309445959620 repeatInterval=86400000 count=1 operation=PendingIntent{480996e8: PendingIntentRecord{480214a0 … Read more