### Get Server Certificate Source: https://github.com/hannesa2/paho.mqtt.android/blob/master/serviceLibrary/src/androidTest/assets/updatingCertificates.md Use this command to fetch the SSL certificate from an MQTT broker. Ensure you capture all certificates in the chain by copying each one to a separate .crt file. ```bash echo -n | openssl s_client -connect broker.hivemq.com:8883 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > eclipse.crt ``` -------------------------------- ### Initialize MqttAndroidClient with Foreground Service (v3.x) Source: https://github.com/hannesa2/paho.mqtt.android/blob/master/README.md For version 3.x on Android O and above, initialize the `MqttAndroidClient` and set up a foreground service with a notification. ```kotlin val client = MqttAndroidClient(context, uri, clientId).apply { setForegroundService(foregroundNotification, 3) } ``` -------------------------------- ### Import Certificate to BKS Keystore Source: https://github.com/hannesa2/paho.mqtt.android/blob/master/serviceLibrary/src/androidTest/assets/updatingCertificates.md Import the obtained certificate into a BKS keystore. This command requires the BouncyCastle provider and its JAR file. Replace 'test.bks' and 'mqtttest' with your desired keystore name and password. ```bash keytool -importcert -v -trustcacerts -file eclipse.crt -alias broker.hivemq.com -keystore "test.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "./bcprov-jdk15on-1.65.jar" -storetype BKS -storepass mqtttest ``` -------------------------------- ### List Certificates in BKS Keystore Source: https://github.com/hannesa2/paho.mqtt.android/blob/master/serviceLibrary/src/androidTest/assets/updatingCertificates.md Verify the contents of your BKS keystore by listing all imported certificates. This command also requires the BouncyCastle provider and its JAR file. ```bash keytool -list -v -keystore test.bks -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "./bcprov-jdk15on-1.65.jar" -storetype BKS -storepass mqtttest ``` -------------------------------- ### Add Library Dependency Source: https://github.com/hannesa2/paho.mqtt.android/blob/master/README.md Add the MQTT Android client library as a dependency in your app's `build.gradle` file. ```gradle dependencies { implementation "com.github.hannesa2:paho.mqtt.android:$latestVersion" } ``` -------------------------------- ### Add Jitpack Repository Source: https://github.com/hannesa2/paho.mqtt.android/blob/master/README.md Include the Jitpack repository in your project's `allprojects` block to use the library. ```gradle allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.