Closed amarpulli1994 closed 5 years ago
@amarpulli1994 Thank you for reporting to us. You need to create the AWSIotMqttManager
object before using it. See https://github.com/awslabs/aws-sdk-android-samples/blob/master/AndroidPubSub/src/com/amazonaws/demo/androidpubsub/PubSubActivity.java#L207 for further details.
AWSIotMqttManager mqttManager = new AWSIotMqttManager(clientId, endpoint);
@kvasukib thnaks for response, I tried initialization AWSIotMqttmanager in android service like below way
String clientId = UUID.randomUUID().toString();
Log.d(LOG_TAG,"ClientId =="+clientId);
mqttManager = new AWSIotMqttManager(clientId,"end point");
Log.d(LOG_TAG,"**message service is created**");
try {
Log.d(LOG_TAG,"**mqtt subscription created**");
mqttManager.subscribeToTopic("home/frontdoor/lock", AWSIotMqttQos.QOS0,
new AWSIotMqttNewMessageCallback() {
@Override
public void onMessageArrived(final String topic, final byte[] data) {
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
String message = new String(data, "UTF-8");
showMessage(topic,message);
Log.d(LOG_TAG, "Message arrived:");
Log.d(LOG_TAG, "Topic: " + topic);
Log.d(LOG_TAG, "Message: " + message);
Toast.makeText(context,"Arrived Messages are:"+message,Toast.LENGTH_SHORT).show();
} catch (UnsupportedEncodingException e) {
Log.e(LOG_TAG, "Message encoding error.", e);
}
}
});
}
});
} catch (Exception e) {
Log.e(LOG_TAG, "Subscription error.", e);
}
But when i was publish the message from one client, didn't get any message which is sent from client.
@amarpulli1994 You need to establish a MQTT connection for publications and subscriptions to work. Please look at the docs for more information.
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.
I m going to run mqtt subscription in android service. When i was run the application, getting null object refernce. My service file:
Log files: