java - 定位 S+(版本 31 及更高版本)需要指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一

标签 java android android-pendingintent exoplayer2.x android-12

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

java.lang.IllegalArgumentException: maa.abc: 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: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) at com.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);

 }

最佳答案

如果使用 java 或 react-native 然后将其粘贴到 app/build.gradle

dependencies {
  // ...
  implementation 'androidx.work:work-runtime:2.7.1'
}

如果使用 Kotlin,那么使用这个

dependencies {
  // ...
  implementation 'androidx.work:work-runtime-ktx:2.7.0'
}

如果有人仍然面临 android 12 的崩溃问题,请确保在 AndroidMenifest.xml 中添加以下内容

 <activity 
   ...
   android:exported="true" // in most cases it is true but based on requirements it can be false also   
>   


   // If using react-native push notifications then make sure to add into it also

 <receiver   
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="true">
 
   //  Similarly
 
 <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="true">

关于java - 定位 S+(版本 31 及更高版本)需要指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70894168/

相关文章:

java - 有没有办法在 Kotlin 类的 block 注释中指定 XML 文件?

java - 如何在 WebView 中自动填充表单字段?

java - 与 db 的并发冲突语句

Android:某些应用程序用户的 NoClassDefFoundError

android - Activity 在娱乐后收到相同的 Intent

android - sendMultipartTextMessage ISms$Stub$Proxy.sendMultipartTextOnSubscription NullPointerException 异常

android - 如何获得 PendingIntent.getActivity 的结果

java - TicTacToe GUI 应用程序重置按钮

java - 单击第二个按钮时的操作

Android:获取所有附近的蜂窝运营商及其信号强度