public void unsubscribe(String topic) { if (androidClient.isConnected()) { try { androidClient.unsubscribe(topic); } catch (MqttException err) { Log.i(DEBUG_TAG, err.getLocalizedMessage()); } } else { Log.i(DEBUG_TAG, "Could not unsubscribe. Client is not connected. Please connect first."); } }
public void disconnect() { if (androidClient.isConnected()) { try { androidClient.disconnect(); Log.i(DEBUG_TAG, "Client Disconnected"); } catch (MqttException err) { Log.i(DEBUG_TAG, err.getLocalizedMessage()); } } else { Log.i(DEBUG_TAG, "Client is already disconnected"); } }
public void publish(String topic, byte[] payload) { if (androidClient.isConnected()) { try { androidClient.publish(topic, payload, qualityOfService, false); } catch (MqttPersistenceException e) { Log.i(DEBUG_TAG, e.getLocalizedMessage()); } catch (MqttException e) { Log.i(DEBUG_TAG, e.getLocalizedMessage()); } } else { Log.i(DEBUG_TAG, "Could not publish. Client is not connected. Please connect first."); } }
public boolean subscribe(final String topic) { if (androidClient.isConnected()) { try { androidClient.subscribe(topic, qualityOfService); isSubscribed = true; return true; } catch (MqttException err) { Log.i(DEBUG_TAG, err.getLocalizedMessage()); return false; } } else { Log.i(DEBUG_TAG, "Could not subscribe. Client is not connected. Please connect first."); return false; } }