定位 S+(版本 31 及更高版本)需要指定FLAG_IMMUTABLE或FLAG_MUTABLE之一
应用在运行时崩溃,并出现以下错误:
java.lang.IllegalArgumentException: maa.abc: Targeting S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定FLAG_IMMUTABLE或FLAG_MUTABLE之一。强烈建议使用FLAG_IMMUTABLE,仅当某些功能依赖于 PendingIntent 的可变性时才使用FLAG_MUTABLE,例如,如果需要将其与内联回复或气泡一起使用。at android.app.PendingIntent.checkFlags(PendingIntent.java:375) at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) at android.app.PendingIntent.getBroadcast(PendingIntent.java:632) at com.google.android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1373) at com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1329) atcom.google.android.exoplayer2.ui.PlayerNotificationManager.(PlayerNotificationManager.java:643) at com.google.android.exoplayer2.ui.PlayerNotificationManager.(PlayerNotificationManager.java:529) at com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:456) at 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);
}