Reputation: 947
I'am using a pending intent to make a notification bar when i play a song in my music app. it used to work perfectly but i have to update my targetSdk to 31 and i run into an error telling me that i need to use some flag with my pendingIntent :
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 some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
Problem is that i use this flag when i declare my pending intent :
val pendingIntent = PendingIntent.getActivity(
applicationContext,
0,
packageManager?.getLaunchIntentForPackage(packageName),
PendingIntent.FLAG_IMMUTABLE
)
So i don't get why it say that i need to use the flag when i already using it ? Am I missing something ?
EDIT
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 or bubbles.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4953)
at android.app.ActivityThread.access$1900(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2300)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.IllegalArgumentException: info.cairn.pro: 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 some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1601)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1557)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.<init>(PlayerNotificationManager.java:862)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.<init>(PlayerNotificationManager.java:793)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.<init>(PlayerNotificationManager.java:757)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:729)
at com.viapresse.presskit.exoplayer.MusicNotificationManager.<init>(MusicNotificationManager.kt:29)
at com.viapresse.presskit.exoplayer.MusicService.onCreate(MusicService.kt:114)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4940)
Upvotes: 2
Views: 876
Reputation: 947
As suggested by @ianhanniballake, the crash was happening in the exoplayer dependency and not in my code...
So i went on https://github.com/google/ExoPlayer/blob/release-v2/RELEASENOTES.md to check all exoplayer update and i found out where they implemented PendingIntent.FLAG_IMMUTABLE funny thing it on 2.14.2 just one iteration above the one i was using.
So i updated the dependency to exoplayer and everything work.
Upvotes: 6