當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageApi類代碼示例

本文整理匯總了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());
        }
    }
}
 
開發者ID:blunden,項目名稱:DoNotDisturbSync,代碼行數:26,代碼來源:WearMessageSenderService.java

示例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();
}
 
開發者ID:blunden,項目名稱:DoNotDisturbSync,代碼行數:28,代碼來源:WearMessageSenderService.java

示例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");
                        }
                    }
                });
    }
}
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:17,代碼來源:MainActivity.java

示例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");
                        }
                    }
                });
    }
}
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:17,代碼來源:MainActivity.java

示例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();
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:26,代碼來源:ActionReceiver.java

示例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();
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:26,代碼來源:UARTCommandsActivity.java

示例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();
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:31,代碼來源:UARTService.java

示例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();
}
 
開發者ID:TheAndroidMaster,項目名稱:APReader,代碼行數:18,代碼來源:Supplier.java

示例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())
            {

            }*/
        }
    });
}
 
開發者ID:spiretos,項目名稱:WeaRemote,代碼行數:18,代碼來源:Communicator.java

示例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();
}
 
開發者ID:kevalpatel2106,項目名稱:android-samples,代碼行數:26,代碼來源:TrackActivity.java

示例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);
                }
            }
        });
    }
}
 
開發者ID:marcouberti,項目名稱:adrenaline_watch_face,代碼行數:23,代碼來源:SonicBoomFace.java

示例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();
                                }
                            });
                        }
                    });
                }
            });
}
 
開發者ID:T-MobileNL,項目名稱:Smartwatch,代碼行數:29,代碼來源:DatalayerUtil.java

示例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();
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:20,代碼來源:ListenerService.java

示例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");}
    };
}
 
開發者ID:juanpomares,項目名稱:Unity-Wear-Controller,代碼行數:19,代碼來源:MainActivity.java


注:本文中的com.google.android.gms.wearable.MessageApi類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。