相关疑难解决方法(0)

以 S+(版本 31 及更高版本)为目标需要指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一

应用程序在运行时崩溃并出现以下错误:

java.lang.IllegalArgumentException:maa.abc:针对 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于可变的 PendingIntent 时才使用 FLAG_MUTABLE,例如,如果需要与内联回复或气泡一起使用。在 android.app.PendingIntent.checkFlags(PendingIntent.java:375) 在 android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) 在 android.app.PendingIntent.getBroadcast(PendingIntent.java:632) 在 com.google。 android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1373) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1329) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager。 (PlayerNotificationManager.java:643) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.(PlayerNotificationManager.java:529) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:456) 在 com .google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:417)

我尝试了所有可用的解决方案,但应用程序在 Android 12 上仍然崩溃。

 @Nullable
 @Override
 public PendingIntent createCurrentContentIntent(@NonNull Player player) {
        Intent intent = new Intent(service, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                        Intent.FLAG_ACTIVITY_SINGLE_TOP |
                        Intent.FLAG_ACTIVITY_NEW_TASK);
        return PendingIntent.getActivity(service, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

 }
Run Code Online (Sandbox Code Playgroud)

java android android-pendingintent exoplayer2.x android-12

71
推荐指数
6
解决办法
7万
查看次数