I followed some tutorial to know how to publish
a message to the broker
from Android device. Below is my attempt, and at this point, I did not find the methods provided in the tutorial like MqttDeliveryTokenAndroid
it is not in the library.
Please let me know how to publish
a message correctly AND please provide a link to the recently updated Paho Android API, the one I am working on now is downloaded from Paho
website and some classes and methods and the one I mentioned above are missing.
Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mqtt_proj_01_layout);
sdCard = Environment.getExternalStorageDirectory();
folder = new File(sdCard + directory);
if (!folder.exists())
folder.mkdir();
final MqttClientPersistence persistenceDataDir = new MqttDefaultFilePersistence(folder.toString());
final MqttAndroidClient client_1 = new MqttAndroidClient(getApplicationContext(), serverURI,
clientID, persistenceDataDir, Ack.AUTO_ACK);
MqttConnectOptions opts = new MqttConnectOptions();
opts.setCleanSession(false);
opts.setWill(WILL_TOPIC, WILL_MSG.getBytes(), 1, true);
opts.setKeepAliveInterval(keepAliveInterval);
final MqttMessage msg = new MqttMessage("33".getBytes());
msg.setQos(1);
msg.setRetained(false);
MqttDeliveryToken deliveryToken = new MqttDeliveryToken();