I have an app that is using Mqtt service with notifications set up. However, the client is not receiving messages when the app is forcefully closed. I notice that there is MqttServce. How do I use it in conjunction with the Android client?
Asked
Active
Viewed 477 times
1 Answers
1
For android you can use Paho Android project, you can intialize a client.
MqttAndroidClient mqttClient = new MqttAndroidClient(BaseApplication.getAppContext(), broker, MQTT_CLIENT_ID);
Set required options and then subscribe to receive messages.
MqttConnectOptions connOpts = new MqttConnectOptions();
Also set following in manifest file.
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
Since the question is very high level would recommend visiting their project on GitHub and going through samples online.
Hoping this helps.
Cheers !

Sachin Thapa
- 3,559
- 4
- 24
- 42
-
Hi, I have done this already, however when I swipe to close the app I stop receiving notifications. I need the ability for retrieval of notifications to persist. Should I use a service or does the client already support something like that? – lawonga Aug 07 '16 at 04:47
-
If the close the app service started will be stopped but yes your messages would be persisted on the server side, so if you connect again you should receive them. – Sachin Thapa Aug 07 '16 at 05:04
-
Hi, yes I have done that with the manifest as well. What if I want the ability to receive messages regardless if the app was closed? Like how whatsapp or facebook messenger does it? – lawonga Aug 07 '16 at 05:50