Jos*_*fem 9 java kotlin android-pendingintent paho android-12
我正在使用 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' 作为 mqtt 服务,并且该应用程序在 Android 12 设备上不断崩溃,并显示以下崩溃日志
java.lang.IllegalArgumentException: app id: 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:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76)
at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1214)
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:1050)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:151)
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的库:
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
Run Code Online (Sandbox Code Playgroud)
小智 24
Eclipse Paho MQTT 库未针对 Android 12 待处理意图进行更新。在那之前,我们可以使用这个 MQTT 客户端。我建议使用 gradle 依赖项,而不是使用我自己的答案中建议的 jar 文件。
在 App Gradle 中,注释此 eclipse 服务依赖项:
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
Run Code Online (Sandbox Code Playgroud)
& 添加这些,而不是当前版本 3.3.5:
//new mqtt library that supports android 12
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.github.hannesa2:paho.mqtt.android:3.3.5'
Run Code Online (Sandbox Code Playgroud)
不要删除 eclipse 客户端依赖项,
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
Run Code Online (Sandbox Code Playgroud)
对于导入,请删除此 eclipse 导入
import org.eclipse.paho.android.service.MqttAndroidClient;
Run Code Online (Sandbox Code Playgroud)
并将其替换为新的:
import info.mqtt.android.service.MqttAndroidClient;
Run Code Online (Sandbox Code Playgroud)
对于 MQTT android 客户端,添加最后一个 Ack 参数,如下所示
client = new MqttAndroidClient(context, serverURI, clientId, Ack.AUTO_ACK);
Run Code Online (Sandbox Code Playgroud)
此外,如果您使用 try catch ,那么MqttException您可以对其进行注释,因为新库不需要相同的内容。
小智 -1
更新firebase库:
实施平台('com.google.firebase:firebase-bom:29.1.0')实施'com.google.firebase:firebase-messaging'
并删除实现 'com.google.firebase:firebase-messaging:23.0.0'
| 归档时间: |
|
| 查看次数: |
10668 次 |
| 最近记录: |