带有 FLAG_IMMUTABLE 的 Kotlin PendingIntent 不适用于 exoplayer

Aqu*_*hka 2 flags android kotlin android-pendingintent exoplayer

当我在音乐应用程序中播放歌曲时,我正在使用待处理的意图来创建通知栏。它曾经完美地工作,但我必须将我的 targetSdk 更新到 31 并且我遇到一个错误,告诉我我需要在endingIntent 中使用一些标志:

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.
Run Code Online (Sandbox Code Playgroud)

问题是我在声明待决意图时使用此标志:

 val pendingIntent = PendingIntent.getActivity(
        applicationContext,
    0,
        packageManager?.getLaunchIntentForPackage(packageName),
        PendingIntent.FLAG_IMMUTABLE
    )
Run Code Online (Sandbox Code Playgroud)

所以我不明白为什么它说我需要在我已经使用该标志时使用它?我错过了什么吗?

编辑

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)
Run Code Online (Sandbox Code Playgroud)

Aqu*_*hka 6

正如 @ianhanniballake 所建议的,崩溃发生在 exoplayer 依赖项中,而不是在我的代码中......

所以我继续在https://github.com/google/ExoPlayer/blob/release-v2/RELEASENOTES.md上检查所有 exoplayer 更新,我发现他们在 2.14.2 上实现了 PendingIntent.FLAG_IMMUTABLE 有趣的事情,只是一次迭代高于我正在使用的那个。

所以我更新了对 exoplayer 的依赖关系,一切正常。