The Paho Android Service is an MQTT client library written in Java for developing applications on Android.
修改原有 eclipse paho mqtt android 项目,支持AndroidX,支持 Android 14
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'io.github.mayzs:paho.mqtt.android:1.2.0'
低版本 gradle 使用 implementation 'io.github.mayzs:paho.mqtt.android:1.2.0@aar'
manifest中 service 标签添加 android:foregroundServiceType="dataSync"
MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId);
android 8.0 及以上添加
client.setForegroundService(notification,1));
1.2.0 版本使用 Worker 替换AlarmManager,去除USE_EXACT_ALARM和SCHEDULE_EXACT_ALARM权限
详情参考 : 原项目https://github.com/eclipse/paho.mqtt.android
MQTT 3.1 | :heavy_check_mark: | Automatic Reconnect | :heavy_check_mark: | |
MQTT 3.1.1 | :heavy_check_mark: | Offline Buffering | :heavy_check_mark: | |
LWT | :heavy_check_mark: | WebSocket Support | :heavy_check_mark: | |
SSL / TLS | :heavy_check_mark: | Standard TCP Support | :heavy_check_mark: | |
Message Persistence | :heavy_check_mark: |
To get started, download Android Studio. You will also need to download the Android SDK. Currently you will need the SDK for 24.Support AndroidX,Support Android 14
The Paho project has been created to provide reliable open-source implementations of open and standard messaging protocols aimed at new, existing, and emerging applications for Machine-to-Machine (M2M) and Internet of Things (IoT). Paho reflects the inherent physical and cost constraints of device connectivity. Its objectives include effective levels of decoupling between devices and applications, designed to keep markets open and encourage the rapid growth of scalable Web and Enterprise middleware and applications.
Eclipse hosts a Nexus repository for those who want to use Maven to manage their dependencies.
Add the repository definition and the dependency definition shown below to your pom.xml.
Replace %REPOURL% with either https://repo.eclipse.org/content/repositories/paho-releases/
for the official releases, or https://repo.eclipse.org/content/repositories/paho-snapshots/
for the nightly snapshots. Replace %VERSION% with the level required .
The latest release version is 1.1.1
and the current snapshot version is 1.1.2-SNAPSHOT
.
<project ...>
<repositories>
<repository>
<id>Eclipse Paho Repo</id>
<url>%REPOURL%</url>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.android.service</artifactId>
<version>%VERSION%</version>
</dependency>
</dependencies>
</project>
If you are using Android Studio and / or Gradle to manage your application dependencies and build then you can use the same repository to get the Paho Android Service. Add the Eclipse Maven repository to your build.gradle
file and then add the Paho dependency to the dependencies
section.
dependencies {
//compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
//compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'io.github.mayzs:paho.mqtt.android:1.1.2'
}
Note: currently you have to include the org.eclipse.paho:org.eclipse.paho.client.mqttv3
dependency as well. We are attempting to get the build to produce an Android AAR
file that contains both the Android service as well as it's dependencies, however this is still experimental. If you wish to try it, remove the org.eclipse.paho:org.eclipse.paho.client.mqttv3
dependency and append @aar
to the end of the Android Service dependency. E.g. org.eclipse.paho:org.eclipse.paho.android.service:1.1.1@aar
If you find that there is functionality missing or bugs in the release version, you may want to try using the snapshot version to see if this helps before raising a feature request or an issue.
`./gradlew clean assemble exportJar
or on Windows: gradlew.bat clean assemble exportJar