В каждом новом сообщении, которое приходит на мой аккаунт, приложение перезагружается. Затем выдает эту ошибку. Я пытался найти решение, но не смог. Я пишу код ошибки в нижней строке.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.edusoft.teacher.myeducare, PID: 7367
java.lang.RuntimeException: Unable to start receiver com.onesignal.GcmBroadcastReceiver: java.lang.IllegalArgumentException: com.edusoft.teacher.myeducare: 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.ActivityThread.handleReceiver(ActivityThread.java:4438)
at android.app.ActivityThread.access$1700(ActivityThread.java:265)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2114)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8168)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
Caused by: java.lang.IllegalArgumentException: com.edusoft.teacher.myeducare: 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:378)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:648)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:635)
at com.onesignal.GenerateNotification.getNewActionPendingIntent(GenerateNotification.java:195)
at com.onesignal.GenerateNotification.createGenericPendingIntentsForNotif(GenerateNotification.java:404)
at com.onesignal.GenerateNotification.showNotification(GenerateNotification.java:388)
at com.onesignal.GenerateNotification.fromJsonPayload(GenerateNotification.java:116)
at com.onesignal.NotificationBundleProcessor.ProcessJobForDisplay(NotificationBundleProcessor.java:115)
at com.onesignal.NotificationBundleProcessor.ProcessFromGCMIntentService(NotificationBundleProcessor.java:98)
at com.onesignal.GcmBroadcastReceiver.startGCMService(GcmBroadcastReceiver.java:138)
at com.onesignal.GcmBroadcastReceiver.processOrderBroadcast(GcmBroadcastReceiver.java:129)
at com.onesignal.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:70)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4425)
... 9 more
я нашел этот код, но либо я его неправильно использовал, либо он не работает должным образом
val updatedPendingIntent = PendingIntent.getActivity(
applicationContext,
NOTIFICATION_REQUEST_CODE,
updatedIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag
)
Использовать это
val updatedPendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
} else {
PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
где именно это написать? Основная деятельность? Поскольку на домашней странице такая же ситуация, у меня такая же проблема на сайте messageFragment.
вы должны создать один класс уведомлений, который расширяет FirebaseMessagingService . в этом классе вы должны создавать уведомление с NotificationCompat.Builder(this, channelId).setContentIntent(updatedPendingIntent)
В вашем журнале отображается ошибка, *
Caused by: java.lang.IllegalArgumentException: com.edusoft.teacher.myeducare: 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.
Приложение Android нацелено на 31 приложение, которое сообщило о большем количестве сбоев (только пользователи ОС Android 12) в обмене сообщениями Firebase (PendingIntent) или в функции уведомлений. Когда приложение находится в состоянии паузы/фона при получении уведомления, происходит его сбой.
Кроме того, может потребоваться повысить версию реализации "androidx.work:work-runtime-ktx:2.5.0"
до последнего обновления
val updatedPendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(
applicationContext, NOTIFICATION_REQUEST_CODE, updatedIntent, PendingIntent.FLAG_IMMUTABLE
)
} else {
PendingIntent.getActivity(
applicationContext, NOTIFICATION_REQUEST_CODE, updatedIntent, PendingIntent.FLAG_ONE_SHOT
)
}
Пожалуйста, объясните подробно, как это связано с трассировкой стека, показанной в вопросе.
Всякий раз, когда в мое приложение приходит сообщение, оно перезапускается. Неважно, в каком фрагменте он находится. У меня возникла эта проблема после того, как я сделал SDK версии 31. Я не знаю, как использовать PendingIntent где угодно.
Если ваше приложение нацелено на Android 12, вы должны указать возможность изменения каждого объекта PendingIntent, который создает ваше приложение. Это дополнительное требование повышает безопасность вашего приложения.
PendingIntent contentIntent = PendingIntent.getActivity(context,NOTIFICATION_REQUEST_CODE, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
мы создаем стандартный тип Intent, который откроет наше приложение, а затем просто оборачиваем его в PendingIntent, прежде чем добавлять его в наше уведомление. В этом случае, поскольку у нас есть точное действие, которое мы хотим выполнить, мы создаем PendingIntent, который не может быть изменен приложением, которому мы передаем его, используя флаг с именем FLAG_IMMUTABLE.
Это изменение необходимо, если вы ориентируетесь на Android S+ и интегрировали FCM в свое приложение.
Вы можете проверить этот блог, если вы планируете перенести свое приложение, совместимое с Android 12.
Вы как-то предоставляете это
PendingIntent
OneSignal? Этот сбой происходит от OneSignal и получения им сообщения FCM на основе трассировки стека. Я предполагаю, что вам нужно обновить свой OneSignal SDK или иным образом поговорить с ними об этом сбое.