我尝试在Android上使用AWSMqttManager连接mqtt。我按照这个示例代码。 https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSubWebSocket。
我在Android版本7.1.1和4.4.4上尝试了应用程序。
Android 7.1.1成功连接。但我无法连接到Android 4.4.4。mqttManager.connect(credentialsProvider, AWSIotMqttClientStatusCallback { status, throwable ->
runOnUiThread {
if (status == AWSIotMqttClientStatus.Connecting) {
logThis("Connecting...")
} else if (status == AWSIotMqttClientStatus.Connected) {
logThis("Connected")
} else if (status == AWSIotMqttClientStatus.Reconnecting) {
if (throwable != null) {
logThis("Connection error.")
}
logThis("Reconnecting")
} else if (status == AWSIotMqttClientStatus.ConnectionLost) {
if (throwable != null) {
logThis("Connection error.")
throwable.printStackTrace()
}
logThis("Disconnected")
} else {
logThis("Disconnected")
}
}
})
它继续重新连接,甚至没有在Android 4.4.4上连接一次。 Aws Iot sdk版本是2.6.12:
compile 'com.amazonaws:aws-android-sdk-iot:2.6.12'
Logcat:
Connecting...
Reconnecting
Reconnecting
Reconnecting
如何解决此问题?