- This library based on Paho from Eclipse
- Simple implementation in your activity or service
- Simple implementation with any MQTT Cloud
- Support java and kotlin
Use any MQTT Cloud like cloudmqtt.com or cloudamqp.com or whatever.
Go to configuration, copy your server, port, username and password. Just like that!
implementation "com.utsman.messaging:smm:${latest_version}"
// for androidx support, just add
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
In AndroidManifest.xml
, add the following element as a child of the <application>
element, by inserting it just before the closing </application>
tag.
<meta-data android:name="com.utsman.smm.SERVER"
android:value="tcp://server_url:port"/>
<meta-data android:name="com.utsman.smm.USERNAME"
android:value="username"/>
<meta-data android:name="com.utsman.smm.PASSWORD"
android:value="password"/>
<meta-data android:name="com.utsman.smm.CLIENT_ID"
android:value="client_id"/>
Smm.subscribe(context, "topic") { senderId, data ->
// message arrived with JSONObject data
val name = data.getString("name")
}
// setup your JSONObject data
val data = JSONObject()
data.putString("name", "Sarah")
// publish your data
Smm.publish(context, "topic", data)
Copyright 2019 Muhammad Utsman
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.