本文整理匯總了Java中org.eclipse.paho.client.mqttv3.MqttMessage.setPayload方法的典型用法代碼示例。如果您正苦於以下問題:Java MqttMessage.setPayload方法的具體用法?Java MqttMessage.setPayload怎麽用?Java MqttMessage.setPayload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.paho.client.mqttv3.MqttMessage
的用法示例。
在下文中一共展示了MqttMessage.setPayload方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: publishMessage
import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
private void publishMessage(String uuid, String major, String minor, String topic) {
if (mqttAndroidClient != null) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("uuid", uuid);
jsonObject.put("major", major);
jsonObject.put("minor", minor);
MqttMessage mqttMessage = new MqttMessage();
mqttMessage.setPayload(jsonObject.toString().getBytes());
mqttAndroidClient.publish(topic, mqttMessage);
boolean logEvent = defaultSharedPreferences.getBoolean(GENEARL_LOG_KEY, false);
if (logEvent) {
String logMessage = context.getString(R.string.published_mqtt_message_to_topic, mqttMessage, topic);
logPersistence.saveNewLog(logMessage, "");
}
} catch (JSONException e) {
logPersistence.saveNewLog(context.getString(R.string.error_publishing_on_topic, topic), "");
Log.e(TAG, context.getString(R.string.error_publishing_on_topic, topic), e);
}
} else {
Log.i(TAG, context.getString(R.string.publish_failed_not_set_up));
}
}
示例2: getMessage
import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public MqttMessage getMessage() {
MqttMessage message = new MqttMessage();
message.setPayload(payload.getBytes());
message.setQos(QoS);
message.setRetained(isRetained());
return message;
}
示例3: valueToMessage
import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
private MqttMessage valueToMessage ( final DataItemValue value )
{
final MqttMessage message = new MqttMessage ();
try
{
message.setPayload ( gson.toJson ( value ).getBytes ( "UTF-8" ) );
}
catch ( final UnsupportedEncodingException e )
{
logger.warn ( "could not convert value", e );
}
message.setRetained ( true );
return message;
}
示例4: sendMessage
import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
@ReactMethod public void sendMessage(String accountId, String messageBody) {
try {
MqttMessage message = new MqttMessage();
message.setPayload(messageBody.getBytes());
mqttAndroidClient.publish(accountId, message);
if(!mqttAndroidClient.isConnected()) {
Log.d(LOG_TAG, mqttAndroidClient.getBufferedMessageCount() + " messages in buffer.");
}
} catch (MqttException e) {
Log.d(LOG_TAG, "Error Publishing: " + e.getMessage());
e.printStackTrace();
}
}