flag_immutable的kotlin待命确实可以与埃克斯皮拉一起使用

发布于 2025-02-07 06:56:45 字数 3331 浏览 4 评论 0原文

当我在音乐应用中播放歌曲时,我正在使用未决的意图来制作通知栏。它曾经很好地工作,但我必须将目标习惯更新为31,我遇到了一个错误,告诉我我需要在我的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.

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

 val pendingIntent = PendingIntent.getActivity(
        applicationContext,
    0,
        packageManager?.getLaunchIntentForPackage(packageName),
        PendingIntent.FLAG_IMMUTABLE
    )

所以我不喜欢't明白了为什么我已经在使用标志时需要使用该标志?我想念什么吗?

编辑

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2025-02-14 06:56:45

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

所以我继续

因此,我将依赖性更新为exoplayer和所有工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文