我刚刚开始学习在 Android Studio 中使用 MQTT 协议。使用mosquitto代理,我能够在发布/订阅窗口之间交换消息。但是,当我通过 android studio 向代理发送消息时,应用程序构建成功,但代理端没有任何显示,系统打印连接失败。相同的代码在 eclipse java 应用程序上运行良好,但在 android 上不起作用,尽管已添加所需的库和依赖项。
请帮助,我在这个基本步骤中缺少什么,以便我可以继续学习。谢谢!
app-build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
// have added following dependencies
provided 'com.google.android.things:androidthings:0.2-devpreview'
provided 'com.google.android.things:androidthings:0.1-devpreview'
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
}
Run Code Online (Sandbox Code Playgroud)
项目-build.gradle
repositories {
jcenter()
maven {
url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zoha.mqttandroidiot">
<!-- Permissions the Application Requires -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" /> …Run Code Online (Sandbox Code Playgroud)