【问题标题】:Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent, On AlarmPingSender定位 S+(版本 31 及更高版本)要求在创建 PendingIntent、On AlarmPingSender 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一
【发布时间】:2021-10-31 03:54:18
【问题描述】:

问题

定位 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。我在将目标 SDK 更新到 31 后得到它。错误总是出现在 AlarmPingSender 之后。但我不知道任何使用 AlarmPingSender 的类。


2021-10-31 10:43:04.990 17031-17341/com.app.mobile D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.com.app.mobile-2e24ccbde048f2e91635651784
2021-10-31 10:43:04.993 17031-17341/com.app.mobile E/AndroidRuntime: FATAL EXCEPTION: MQTT Rec: com.app.mobile-2e24ccbde048f2e91635651784
    Process: com.app.mobile, PID: 17031
    java.lang.IllegalArgumentException: com.app.mobile: 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 org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76)
        at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1150)
        at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:987)
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118)
        at java.lang.Thread.run(Thread.java:920)

我已经做了什么

  • 将 WorkManager 升级到 2.7.0
  • 设置 AllProject 强制使用 WorkManager 到 2.7.0
  • 将所有现有的 PendingIntent 更改为使用 FLAG_IMMUTABLE
  • 有些旧代码仍在使用 gcm 并禁用它
  • 更新所有 Firebase 软件包(有人说是因为更高版本的分析)

使用的库

  • OneSignal
  • Qiscus
  • Firebase
  • 工作经理

【问题讨论】:

标签: android kotlin android-pendingintent android-workmanager android-12


【解决方案1】:

我遇到了这个崩溃,但没有第 3 方库。使用最新版本添加此导入将修复崩溃。

implementation 'androidx.work:work-runtime-ktx:2.7.0-beta01'

【讨论】:

  • 为我工作。在我的情况下改为: implementation("androidx.work:work-runtime-ktx:2.7.1")
【解决方案2】:

将以下内容添加到您的 build.gradle(app) 依赖项中。

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

  // For Kotlin
  implementation 'androidx.work:work-runtime-ktx:2.7.1'
}

【讨论】:

    【解决方案3】:

    可能的解决方案

    将谷歌分析升级到 Firebase 分析。希望它能解决你的问题。同时升级你正在使用的所有库。

    对我来说,以下解决方案可以解决问题。

    PendingIntent.FLAG_IMMUTABLE 添加到您的待处理意图中。

    这是一个例子-

    PendingIntent pendingIntent = PendingIntent.getActivity(this, alarmID, notificationIntent, PendingIntent.FLAG_IMMUTABLE);

    有关更多信息,请点击此链接 - https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE

    【讨论】:

    • 我已经尝试过了,但问题仍然存在。
    • 更新 Firebase 库为我解决了这个问题。
    • 如何将谷歌分析升级到 Firebase 分析?
    【解决方案4】:

    在多次尝试解决此问题后,我放弃并尝试联系 Qiscus。他们发布了新版本来处理这个 Pending Intent 行为变化。因此,如果有人使用 Qiscus 并遇到此错误,您可以使用 latest 标签

    https://github.com/qiscus/qiscus-sdk-android/releases/tag/1.3.35

    【讨论】:

      【解决方案5】:

      尝试添加报警权限

      <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
      

      【讨论】:

        【解决方案6】:

        除了其他人的答案我改变了:

        implementation 'com.google.firebase:firebase-messaging:20.0.0'
        

        到:

        implementation 'com.google.firebase:firebase-messaging:23.0.0'
        

        它现在可以工作了。

        【讨论】:

          【解决方案7】:

          这可能是库版本的问题。如果您的项目中有旧版本库,则必须将其更新到最新版本。

          所以,更新工作运行时和firebase消息库版本如下,

          dependencies {
              // For Java
              implementation 'androidx.work:work-runtime:2.7.1' 
              // For Kotlin
              implementation 'androidx.work:work-runtime-ktx:2.7.1'
              implementation 'com.google.firebase:firebase-messaging:23.0.0'
              ...
          }
          

          另外,确保待处理的意图代码是这样的,

          PendingIntent pendingIntent = PendingIntent.getActivity(this, alarmID, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2022-10-05
            • 2022-01-08
            • 2021-09-29
            • 2023-01-01
            • 2021-09-14
            • 1970-01-01
            • 1970-01-01
            • 2023-01-30
            相关资源
            最近更新 更多