La aplicación falla en tiempo de ejecución con el siguiente error:
java.lang.IllegalArgumentException: maa.abc: la orientación a S+ (versión 31 y superior) requiere que se especifique FLAG_IMMUTABLE o FLAG_MUTABLE al crear un PendingIntent. Considere seriamente usar FLAG_IMMUTABLE, solo use FLAG_MUTABLE si alguna funcionalidad depende de que PendingIntent sea mutable, por ejemplo, si necesita usarse con respuestas en línea o burbujas. en android.app.PendingIntent.checkFlags(PendingIntent.java:375) en android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) en android.app.PendingIntent.getBroadcast(PendingIntent.java:632) en com.google. android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1373) en com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1329) en com.google.android.exoplayer2.ui.PlayerNotificationManager. (PlayerNotificationManager.java:643) en com.google.android.exoplayer2.ui.PlayerNotificationManager.(PlayerNotificationManager.java:529) en com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:456) en com .google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:417)
Probé todas las soluciones disponibles, pero la aplicación sigue fallando en 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); }Verifique y actualice la versión de dependencia de exoplayer a la última
android.app.PendingIntent.getBroadcast() utilizado anteriormente para devolver
@Nullable @Override private static PendingIntent createBroadcastIntent( String action, Context context, int instanceId) { Intent intent = new Intent(action).setPackage(context.getPackageName()); intent.putExtra(EXTRA_INSTANCE_ID, instanceId); return PendingIntent.getBroadcast( context, instanceId, intent, PendingIntent.FLAG_UPDATE_CURRENT); }Si observa cuidadosamente, falta PendingIntent.FLAG_IMMUTABLE aquí en el fragmento anterior
Ahora se ha actualizado para devolver lo siguiente
@Nullable @Override private static PendingIntent createBroadcastIntent( String action, Context context, int instanceId) { Intent intent = new Intent(action).setPackage(context.getPackageName()); intent.putExtra(EXTRA_INSTANCE_ID, instanceId); int pendingFlags; if (Util.SDK_INT >= 23) { pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE; } else { pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT; } return PendingIntent.getBroadcast(context, instanceId, intent, pendingFlags); }Si usa java o react-native, pegue esto dentro de app/build.gradle
dependencies { // ... implementation 'androidx.work:work-runtime:2.7.1' }Si usa Kotlin, use esto
dependencies { // ... implementation 'androidx.work:work-runtime-ktx:2.7.0' }y si alguien todavía enfrenta el problema de bloqueo para Android 12, asegúrese de agregar lo siguiente en 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">