本文整理匯總了Java中com.google.android.gms.wearable.MessageApi類的典型用法代碼示例。如果您正苦於以下問題:Java MessageApi類的具體用法?Java MessageApi怎麽用?Java MessageApi使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageApi類屬於com.google.android.gms.wearable包,在下文中一共展示了MessageApi類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleActionSendMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Handle the message sending action in the provided background thread.
*/
private void handleActionSendMessage(String mode) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
if (!(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT, TimeUnit.SECONDS);
}
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
// Send the Do Not Disturb mode message to all devices (nodes)
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), DND_SYNC_PREFIX, mode.getBytes()).await();
if (!result.getStatus().isSuccess()){
Log.e(TAG, "Failed to send message to " + node.getDisplayName());
} else {
Log.i(TAG, "Successfully sent message " + mode + " to " + node.getDisplayName());
}
}
}
示例2: handleActionSendMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Handle the message sending action in the provided background thread.
*/
private void handleActionSendMessage(String mode) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
if (!(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT, TimeUnit.SECONDS);
}
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
// Send the Do Not Disturb mode message to all devices (nodes)
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), DND_SYNC_PREFIX, mode.getBytes()).await();
if (!result.getStatus().isSuccess()){
Log.e(TAG, "Failed to send message to " + node.getDisplayName());
} else {
Log.i(TAG, "Successfully sent message " + mode + " to " + node.getDisplayName());
}
}
//mGoogleApiClient.disconnect();
}
示例3: sendMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
private void sendMessage(String message) {
if (mNode != null && mGoogleApiClient != null) {
Wearable.MessageApi.sendMessage(mGoogleApiClient, mNode.getId(), WEAR_PATH, message.getBytes())
.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
if (!sendMessageResult.getStatus().isSuccess()) {
Log.d("packtchat", "Failed message: " +
sendMessageResult.getStatus().getStatusCode());
} else {
Log.d("packtchat", "Message succeeded");
}
}
});
}
}
示例4: sendMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
private void sendMessage(String city) {
if (mNode != null && mGoogleApiClient != null) {
Wearable.MessageApi.sendMessage(mGoogleApiClient, mNode.getId(), WEAR_PATH, city.getBytes())
.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
if (!sendMessageResult.getStatus().isSuccess()) {
Log.d("packtchat", "Failed message: " +
sendMessageResult.getStatus().getStatusCode());
} else {
Log.d("packtchat", "Message succeeded");
}
}
});
}
}
示例5: sendMessageToHandheld
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Sends the given message to the handheld.
* @param path message path
* @param message the message
*/
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String path, final @NonNull String message) {
new Thread(new Runnable() {
@Override
public void run() {
final GoogleApiClient client = new GoogleApiClient.Builder(context)
.addApi(Wearable.API)
.build();
client.blockingConnect();
final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
for(Node node : nodes.getNodes()) {
final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), path, message.getBytes()).await();
if (!result.getStatus().isSuccess()){
Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName());
}
}
client.disconnect();
}
}).start();
}
示例6: sendMessageToHandheld
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Sends the given command to the handheld.
*
* @param command the message
*/
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String command) {
new Thread(new Runnable() {
@Override
public void run() {
final GoogleApiClient client = new GoogleApiClient.Builder(context)
.addApi(Wearable.API)
.build();
client.blockingConnect();
final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
for (Node node : nodes.getNodes()) {
final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), Constants.UART.COMMAND, command.getBytes()).await();
if (!result.getStatus().isSuccess()) {
Log.w(TAG, "Failed to send " + Constants.UART.COMMAND + " to " + node.getDisplayName());
}
}
client.disconnect();
}
}).start();
}
示例7: sendMessageToWearables
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Sends the given message to all connected wearables. If the path is equal to {@link Constants.UART#DEVICE_DISCONNECTED} the service will be stopped afterwards.
* @param path message path
* @param message the message
*/
private void sendMessageToWearables(final @NonNull String path, final @NonNull String message) {
if(mGoogleApiClient.isConnected()) {
new Thread(new Runnable() {
@Override
public void run() {
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
for(Node node : nodes.getNodes()) {
Logger.v(getLogSession(), "[WEAR] Sending message '" + path + "' to " + node.getDisplayName());
final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, message.getBytes()).await();
if(result.getStatus().isSuccess()){
Logger.i(getLogSession(), "[WEAR] Message sent");
} else {
Logger.w(getLogSession(), "[WEAR] Sending message failed: " + result.getStatus().getStatusMessage());
Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName());
}
}
if (Constants.UART.DEVICE_DISCONNECTED.equals(path))
stopService();
}
}).start();
} else {
if (Constants.UART.DEVICE_DISCONNECTED.equals(path))
stopService();
}
}
示例8: sendMessageToDevice
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
private void sendMessageToDevice(final String key) {
new Thread(new Runnable() {
@Override
public void run() {
if (mGoogleApiClient == null) {
mGoogleApiClient = (new com.google.android.gms.common.api.GoogleApiClient.Builder(ConfigDataListenerService.this)).addConnectionCallbacks(ConfigDataListenerService.this).addOnConnectionFailedListener(ConfigDataListenerService.this).addApi(Wearable.API).build();
}
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
if (nodes != null && nodes.getNodes() != null) {
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), key, null).await();
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Error during sending message");
} else {
Log.i(TAG, "Success!! sent to: " + node.getDisplayName());
}
}
}
}
}).start();
}
開發者ID:mladenbabic,項目名稱:Advanced_Android_Development_Wear,代碼行數:22,代碼來源:ConfigDataListenerService.java
示例9: sendWearableMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
public void sendWearableMessage(String message, @Nullable final AsyncListener<Status> listener) {
if (node != null && apiClient != null && apiClient.isConnected()) {
Wearable.MessageApi.sendMessage(apiClient, node.getId(), WEAR_PATH, message.getBytes()).setResultCallback(
new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(@NonNull MessageApi.SendMessageResult sendMessageResult) {
if (listener != null) {
Status status = sendMessageResult.getStatus();
if (status.isSuccess())
listener.onTaskComplete(status);
else listener.onFailure();
}
}
}
);
} else if (listener != null) listener.onFailure();
}
示例10: sendMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
public void sendMessage(String command, byte[] data)
{
if (mNode == null)
return;
Wearable.MessageApi.sendMessage(mGoogleApiClient, mNode.getId(), command, data).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>()
{
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult)
{
/*if (!sendMessageResult.getStatus().isSuccess())
{
}*/
}
});
}
示例11: sendStepCountMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Send the current step count to the phone. This does not require guarantee of message delivery. As, if
* the message is not delivered, the count will get updated when second message gets delivered.
* So, we are using messages api for passing the data that are usful at the current moment only.
* <p>
* <B>Note: </B> Messages will block the UI thread while sending. So, we should send messages in background
* thread only.
*
* @param stepCount current step count.
*/
private void sendStepCountMessage(final String stepCount) {
new Thread(new Runnable() {
@Override
public void run() {
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
mGoogleApiClient, node.getId(), STEP_COUNT_MESSAGES_PATH, stepCount.getBytes()).await();
//check if the message is delivered?
Log.d("Messages Api", result.getStatus().isSuccess() ? "Sent successfully" : "Sent failed.");
}
}
}).start();
}
示例12: fireMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
protected void fireMessage(final String command) {
if (phoneNodeId == null) {
//bad, we cannot send message
} else {
//fire the message to the first connected node in list
Log.d(TAG, "Sending message to Node with ID: " + phoneNodeId);
PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(mGoogleApiClient, phoneNodeId, command, null);
messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
Status status = sendMessageResult.getStatus();
Log.d(TAG, "Status: " + status.toString());
if (status.getStatusCode() != WearableStatusCodes.SUCCESS) {
Log.e(TAG,"Something go wrong during sending command... "+command);
} else {
Log.d(TAG,"Message sent successfully to node. "+command);
}
}
});
}
}
示例13: getSendMessage
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
/**
* Method to send a message to all other nodes.
*
* @param googleApiClient a connected googleApiClient
* @param path path to send message to
* @param data payload to send
* @return Observable that emits whether the message was sent
*/
public static Observable<Boolean> getSendMessage(final GoogleApiClient googleApiClient, final String path, final byte[] data) {
return NodeUtil.getRemoteNodeId(googleApiClient)
.flatMap(new Func1<String, Observable<Boolean>>() {
@Override
public Observable<Boolean> call(final String nodeId) {
return Observable.create(new Observable.OnSubscribe<Boolean>() {
@Override
public void call(final Subscriber<? super Boolean> subscriber) {
Wearable.MessageApi.sendMessage(googleApiClient, nodeId, path, data).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
subscriber.onNext(sendMessageResult.getStatus().isSuccess());
subscriber.onCompleted();
}
});
}
});
}
});
}
示例14: onDestroy
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
@Override
public void onDestroy() {
super.onDestroy();
if (googleApiClient != null && googleApiClient.isConnected()) {
googleApiClient.disconnect();
}
if (googleApiClient != null) {
Wearable.MessageApi.removeListener(googleApiClient, this);
}
Log.d(TAG, "Stop Sensors");
stopMeasurement();
if (mPrefs.getBoolean("enable_wearG5", true)) {
Log.d(TAG, "Start BT Collection Service");
stopBtService();
}
}
示例15: initConnectionCallbacks
import com.google.android.gms.wearable.MessageApi; //導入依賴的package包/類
private void initConnectionCallbacks()
{
mConnectionCallbacks=new GoogleApiClient.ConnectionCallbacks()
{
@Override
public void onConnected(@Nullable Bundle bundle)
{
AddTextInterface("onConnected...");
initMessageListener();
Wearable.MessageApi.addListener(mApiClient, mMessageListener);
sendMessageChecking(PublicConstants.START_ACTIVITY, "");
AddTextInterface("Sended START_ACTIVITY command");
}
@Override
public void onConnectionSuspended(int i) {AddTextInterface("Connection suspended");}
};
}