com.google.android.gms.wearable.MessageApi Java Examples
The following examples show how to use
com.google.android.gms.wearable.MessageApi.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteSensorManager.java From SensorDashboard with Apache License 2.0 | 6 votes |
private void controlMeasurementInBackground(final String path) { if (validateConnection()) { List<Node> nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await().getNodes(); Log.d(TAG, "Sending to nodes: " + nodes.size()); for (Node node : nodes) { Log.i(TAG, "add node " + node.getDisplayName()); Wearable.MessageApi.sendMessage( googleApiClient, node.getId(), path, null ).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { Log.d(TAG, "controlMeasurementInBackground(" + path + "): " + sendMessageResult.getStatus().isSuccess()); } }); } } else { Log.w(TAG, "No connection possible"); } }
Example #2
Source File: WatchSettingsActivity.java From android-wear-gopro-remote with Apache License 2.0 | 6 votes |
void sendWearMessage(String path, byte[] data) { mLoadingPanel.setVisibility(View.VISIBLE); WearApplication app = (WearApplication)getApplication(); if(app != null) { if(app.MessageSender != null) { app.MessageSender.sendWearMessage(path, data, new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if(!sendMessageResult.getStatus().isSuccess()) { mLoadingPanel.setVisibility(View.GONE); } } }); return; } else { Logger.error(TAG, "WearApplication.MessageSender is null."); } } else { Logger.error(TAG, "Application is not WearApplication"); } mLoadingPanel.setVisibility(View.GONE); }
Example #3
Source File: MobileMainActivity.java From android-wear-gopro-remote with Apache License 2.0 | 6 votes |
@Override protected void onPause() { super.onPause(); if(mShakeDetectActivity != null) { mShakeDetectActivity.stopDetecting(); } if(mWatchSettingsChanged) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (mGoogleApiClient.isConnected() && mWearNode != null) { WearSettings wearSettings = new WearSettings(); wearSettings.loadFromPreferences(this, prefs); Wearable.MessageApi.sendMessage(mGoogleApiClient, mWearNode.getId(), WearMessages.MESSAGE_SET_WEAR_SETTINGS, wearSettings.rawData).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { fCurrentWearSettings.saveToPreferences(MobileMainActivity.this, prefs); } } }); } else { fCurrentWearSettings.saveToPreferences(MobileMainActivity.this, prefs); } } disconnectGoogleApiClient(); }
Example #4
Source File: WatchMainActivity.java From android-wear-gopro-remote with Apache License 2.0 | 6 votes |
@Override protected void onDestroy() { Context context = getApplicationContext(); WatchDataLayerListenerService.enable(context); PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this); if(!mDontSendDisconnect) sendToPhone(WearMessages.MESSAGE_DISCONNECT, null, null, false); Wearable.MessageApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); if(mUpdateRecordingTimeTimer != null) mUpdateRecordingTimeTimer.stop(); if(mReconnectTimer != null) mReconnectTimer.stop(); if(mShakeDetectActivity != null) mShakeDetectActivity.clear(); GoProStatus.LastCameraStatus = null; ThumbCache.clear(); WearApplication app = (WearApplication)getApplication(); if(app != null) { app.MessageSender = null; } super.onDestroy(); if(mMustKillProcOnDestroy) { android.os.Process.killProcess(android.os.Process.myPid()); } }
Example #5
Source File: SendByteArrayToNode.java From ExceptionWear with Apache License 2.0 | 6 votes |
public void run() { if ((objectArray.length / 1024) > 100) { throw new RuntimeException("Object is too big to push it via Google Play Services"); } GoogleApiClient googleApiClient = SendWearManager.getInstance(context); googleApiClient.blockingConnect(WearExceptionTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result; result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearExceptionTools.MESSAGE_EXCEPTION_PATH, objectArray).await(); if (!result.getStatus().isSuccess()) { Log.v(WearExceptionTools.EXCEPTION_WEAR_TAG, "ERROR: failed to send Message via Google Play Services"); } } }
Example #6
Source File: WearActivity.java From LibreAlarm with GNU General Public License v3.0 | 6 votes |
@Override protected void onStop() { Log.i(TAG, "onStop"); if (mHandler != null) mHandler.removeCallbacksAndMessages(null); if (mVibrator != null) mVibrator.cancel(); if (mNfcAdapter != null) { mNfcAdapter.disableReaderMode(this); } if ((mGoogleApiClient != null) && (mGoogleApiClient.isConnected())) { Wearable.MessageApi.removeListener(mGoogleApiClient, this); mGoogleApiClient.disconnect(); } if (mRootTools != null) mRootTools.executeScripts(false, 15000); if ((mWakeLock != null) && (mWakeLock.isHeld())) mWakeLock.release(); finish(); super.onStop(); }
Example #7
Source File: WearableApi.java From LibreAlarm with GNU General Public License v3.0 | 6 votes |
public static void sendMessage(final GoogleApiClient client, final String command, final byte[] message, final ResultCallback<MessageApi.SendMessageResult> listener) { new Thread(new Runnable() { @Override public void run() { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes( client ).await(); for(Node node : nodes.getNodes()) { Log.i(TAG, "sending to " + node.getId() + ", command: " + command); PendingResult<MessageApi.SendMessageResult> pR = Wearable.MessageApi.sendMessage(client, node.getId(), command, message); if (listener != null) pR.setResultCallback(listener); } } }).start(); }
Example #8
Source File: SendByteArrayToNode.java From BusWear with Apache License 2.0 | 6 votes |
public void run() { GoogleApiClient googleApiClient = SendWearManager.getInstance(context); googleApiClient.blockingConnect(WearBusTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result; if (sticky) { result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH_STICKY + WearBusTools.CLASS_NAME_DELIMITER + clazzToSend.getName(), objectArray).await(); } else { result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH + WearBusTools.CLASS_NAME_DELIMITER + clazzToSend.getName(), objectArray).await(); } if (!result.getStatus().isSuccess()) { Log.v(WearBusTools.BUSWEAR_TAG, "ERROR: failed to send Message via Google Play Services to node " + node.getDisplayName()); } } }
Example #9
Source File: Emmet.java From Wear-Emmet with Apache License 2.0 | 6 votes |
public Emmet onCreate(Context context, ConnectionListener connectionListener) { mConnectionListener = connectionListener; mApiClient = new GoogleApiClient.Builder(context.getApplicationContext()) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); Wearable.MessageApi.addListener(mApiClient, new MessageApi.MessageListener() { @Override public void onMessageReceived(MessageEvent messageEvent) { onMessageReceived(messageEvent); } }); Wearable.DataApi.addListener(mApiClient, new DataApi.DataListener() { @Override public void onDataChanged(DataEventBuffer dataEventBuffer) { onDataChanged(dataEventBuffer); } }); mApiClient.connect(); return this; }
Example #10
Source File: ListenerService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@Override public void onDestroy() { super.onDestroy(); if (googleApiClient != null && googleApiClient.isConnected()) { googleApiClient.disconnect(); } if (googleApiClient != null) { Wearable.MessageApi.removeListener(googleApiClient, this); Wearable.ChannelApi.removeListener(googleApiClient, this); } Log.d(TAG, "Stop Sensors"); stopMeasurement(); if (mPrefs.getBoolean("enable_wearG5", true)) { Log.d(TAG, "Start BT Collection Service"); stopBtService(); } }
Example #11
Source File: Emmet.java From Wear-Emmet with Apache License 2.0 | 6 votes |
protected void sendMessage(final String path, final String message) { if (mApiClient != null) { if (mApiClient.isConnected()) { new Thread(new Runnable() { @Override public void run() { final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage( mApiClient, node.getId(), path, message.getBytes()).await(); } } }).start(); } else { mWaitingMessageItems.add(new Pair<>(path, message)); mApiClient.connect(); } } }
Example #12
Source File: ActionReceiver.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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(() -> { 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(); }
Example #13
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override //OnConnectionFailedListener public void onConnectionFailed(ConnectionResult result) { if (mResolvingError) { // Already attempting to resolve an error. return; } else if (result.hasResolution()) { try { mResolvingError = true; result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR); } catch (IntentSender.SendIntentException e) { // There was an error with the resolution intent. Try again. mGoogleApiClient.connect(); } } else { Log.e(TAG, "Connection to Google API client has failed"); mResolvingError = false; mStartActivityBtn.setEnabled(false); mSendPhotoBtn.setEnabled(false); Wearable.DataApi.removeListener(mGoogleApiClient, this); Wearable.MessageApi.removeListener(mGoogleApiClient, this); Wearable.NodeApi.removeListener(mGoogleApiClient, this); } }
Example #14
Source File: OkWear.java From OkWear with Apache License 2.0 | 6 votes |
@Override public void sendMessageAllAsync(@Nullable final byte[] payload, @Nullable String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) { if (path == null) { path = DEFAULT_MESSAGE_API_PATH; } final String finalPath = path; mHelper.getNodes(new NodeChangeListener() { @Override public void onReceiveNodes(List<Node> nodes) { for (Node node : nodes) { sendMessageAsync(node, payload, finalPath, listener); } } }); }
Example #15
Source File: DataUtils.java From wear with MIT License | 6 votes |
protected Void doInBackground(Object... params) { GoogleApiClient client = (GoogleApiClient)params[0]; NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi .getConnectedNodes(client) .await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result = Wearable.MessageApi .sendMessage(client, node.getId(), (String)params[1], ((String)params[2]).getBytes()) .await(); if (!result.getStatus().isSuccess()) { Log.e(TAG, "could not send message (" + result.getStatus() + ")"); } } return null; }
Example #16
Source File: OkWear.java From OkWear with Apache License 2.0 | 6 votes |
@Override public void sendMessageAll(@Nullable final byte[] payload, @Nullable String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) { if (path == null) { path = DEFAULT_MESSAGE_API_PATH; } final String finalPath = path; mHelper.getNodes(new NodeChangeListener() { @Override public void onReceiveNodes(List<Node> nodes) { for (Node node : nodes) { sendMessage(node, payload, finalPath, listener); } } }); }
Example #17
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override protected void onStop() { Wearable.DataApi.removeListener(mGoogleApiClient, this); Wearable.MessageApi.removeListener(mGoogleApiClient, this); // Tell the wearable to end the quiz (counting unanswered questions as skipped), and then // disconnect mGoogleApiClient. DataMap dataMap = new DataMap(); dataMap.putInt(NUM_CORRECT, mNumCorrect); dataMap.putInt(NUM_INCORRECT, mNumIncorrect); if (mHasQuestionBeenAsked) { mNumSkipped += 1; } mNumSkipped += mFutureQuestions.size(); dataMap.putInt(NUM_SKIPPED, mNumSkipped); if (mNumCorrect + mNumIncorrect + mNumSkipped > 0) { sendMessageToWearable(QUIZ_EXITED_PATH, dataMap.toByteArray()); } clearQuizStatus(); super.onStop(); }
Example #18
Source File: TrackActivity.java From android-samples with Apache License 2.0 | 6 votes |
/** * 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(); }
Example #19
Source File: MainActivity.java From arcgis-runtime-demos-android with Apache License 2.0 | 6 votes |
private void sendEvent(final byte[] 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()) { MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), MESSAGE_PATH, message).await(); if (!result.getStatus().isSuccess()) { Log.e("test", "error"); } else { Log.i("test", "success!! sent to: " + node.getDisplayName()); } } } }).start(); } else { Log.e("test", "google api not connected"); } }
Example #20
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 6 votes |
/** * send message * you don't have to send anything * * @param node 送信先node * @param payload * @param path * @param listener */ public void sendMessage(@NonNull final Node node, @Nullable final byte[] payload, @NonNull final String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) { final PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, payload); messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(final MessageApi.SendMessageResult sendMessageResult) { Log.d(TAG, "Status: " + sendMessageResult.getStatus()); if (listener != null) { listener.onResult(sendMessageResult); } } }); }
Example #21
Source File: WatchMainActivity.java From android-wear-gopro-remote with Apache License 2.0 | 5 votes |
private boolean sendToPhone(String path, byte[] data, final ResultCallback<MessageApi.SendMessageResult> callback, boolean showSpinner) { if (mPhoneNode != null) { long diff = System.currentTimeMillis() - mLastMessageToPhone; if(diff <= 1000) { if(Logger.DEBUG) Logger.debug(TAG, "Last message to phone was %d millis ago", diff); return false; } if(showSpinner) showSpinner(); if(Logger.DEBUG) Logger.debug(TAG, "Message sent %s", path); if (mShakeDetectActivity != null) mShakeDetectActivity.stopDetecting(); PendingResult<MessageApi.SendMessageResult> pending = Wearable.MessageApi.sendMessage(mGoogleApiClient, mPhoneNode.getId(), path, data); pending.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult result) { if (callback != null) { callback.onResult(result); } if (result.getStatus().isSuccess()) { mLastMessageToPhone = System.currentTimeMillis(); } else { setFailStatusMessage(R.string.label_watch_disconnected, R.drawable.ic_retry); Logger.warning(TAG, "Failed to send Message: " + result.getStatus()); } } }); return true; } else { Logger.error(TAG, String.format("Tried to send message (%s) before device was found.", path)); return false; } }
Example #22
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 5 votes |
public void disconnect() { if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); Wearable.DataApi.removeListener(mGoogleApiClient, this); Wearable.MessageApi.removeListener(mGoogleApiClient, this); Wearable.NodeApi.removeListener(mGoogleApiClient, this); } }
Example #23
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 5 votes |
@Override public void onConnected(final Bundle bundle) { Log.d(TAG, "onConnected"); Wearable.DataApi.addListener(mGoogleApiClient, this); Wearable.MessageApi.addListener(mGoogleApiClient, this); Wearable.NodeApi.addListener(mGoogleApiClient, this); }
Example #24
Source File: SendMessageTask.java From OkWear with Apache License 2.0 | 5 votes |
@Override protected MessageApi.SendMessageResult doInBackground(Object... args) { final MessageApi.SendMessageResult messageResult = Wearable.MessageApi.sendMessage(googleApiClient, id, path, payload).await(); return messageResult; }
Example #25
Source File: OkWear.java From OkWear with Apache License 2.0 | 5 votes |
@Override public void sendMessage(@NonNull final Node node, @Nullable final byte[] payload, @Nullable String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) { if (path == null) { path = DEFAULT_MESSAGE_API_PATH; } mHelper.sendMessage(node, payload, path, listener); }
Example #26
Source File: OkWear.java From OkWear with Apache License 2.0 | 5 votes |
@Override public void sendMessageAsync(@NonNull final Node node, @Nullable final byte[] payload, @Nullable String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) { if (path == null) { path = DEFAULT_MESSAGE_API_PATH; } mHelper.sendMessageAsync(node, payload, path, listener); }
Example #27
Source File: SendMessageTask.java From OkWear with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(final MessageApi.SendMessageResult result) { if (listener != null) { listener.onResult(result); } return; }
Example #28
Source File: MainActivity.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) { Log.e("ETSMobile-Wear", connectionResult.getErrorMessage()); return null; } MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage( googleApiClient, Utils.getRemoteNodeId(googleApiClient), "/today_req", null) .await(); if (result.getStatus().isSuccess()) { Log.d("wearThread", "SUCCESS : Message sent"); } else { Log.d("wearThread", "ERROR: failed to send Message"); } return null; }
Example #29
Source File: WearMessageListenerService.java From AnkiDroid-Wear with GNU General Public License v2.0 | 5 votes |
private void fireMessage(final byte[] data, final String path,final int retryCount) { PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient); nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() { @Override public void onResult(NodeApi.GetConnectedNodesResult result) { for (int i = 0; i < result.getNodes().size(); i++) { Node node = result.getNodes().get(i); Log.v(TAG, "Phone firing message with path : " + path); PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, data); messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { Status status = sendMessageResult.getStatus(); Timber.d("Status: " + status.toString()); if (status.getStatusCode() != WearableStatusCodes.SUCCESS) { if(!status.isSuccess()) { if (retryCount > 5) return; soundThreadHandler.postDelayed(new Runnable() { @Override public void run() { fireMessage(data, path, retryCount + 1); } }, 1000 * retryCount); } } if (path.equals(CommonIdentifiers.P2W_CHANGE_SETTINGS)) { Intent messageIntent = new Intent(); messageIntent.setAction(Intent.ACTION_SEND); messageIntent.putExtra("status", status.getStatusCode()); LocalBroadcastManager.getInstance(WearMessageListenerService.this).sendBroadcast(messageIntent); } } }); } } }); }
Example #30
Source File: MainActivity.java From wear-notify-for-reddit with Apache License 2.0 | 5 votes |
@Override public void onConnected(Bundle bundle) { Wearable.MessageApi.sendMessage(mGoogleApiClient, "", Constants.PATH_REFRESH, null) .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult result) { Logger.log("Requested a refresh, result: " + result.getStatus()); finishActivity(); } }); }