@Override public void onPause() { super.onPause(); Wearable.getMessageClient(this).removeListener(this); }
@Override public void onResume() { super.onResume(); Wearable.getMessageClient(this).addListener(this); }
public void run() { try { JSONObject json = new JSONObject(); json.put("severity", Character.toString(severity)); json.put("message", message); json.put("exception", exception); byte[] data = json.toString().getBytes(); if (bestNodeId != null) { Wearable.getMessageClient(context).sendMessage(bestNodeId, "/apde_receive_logs", data); } } catch (Exception e) { // Don't call printStackTrace() because that would make an infinite loop Log.e("apde", e.toString()); } } });
@Override public void onPause() { super.onPause(); Wearable.getMessageClient(this).removeListener(this); }
@Override public void onResume() { super.onResume(); Wearable.getMessageClient(this).addListener(this); }
@Override public void onResume() { super.onResume(); mDataItemGeneratorFuture = mGeneratorExecutor.scheduleWithFixedDelay( new DataItemGenerator(), 1, 5, TimeUnit.SECONDS); mStartActivityBtn.setEnabled(true); mSendPhotoBtn.setEnabled(mCameraSupported); // Instantiates clients without member variables, as clients are inexpensive to create and // won't lose their listeners. (They are cached and shared between GoogleApi instances.) Wearable.getDataClient(this).addListener(this); Wearable.getMessageClient(this).addListener(this); Wearable.getCapabilityClient(this) .addListener(this, Uri.parse("wear://"), CapabilityClient.FILTER_REACHABLE); }
@WorkerThread private void sendStartActivityMessage(String node) { Task<Integer> sendMessageTask = Wearable.getMessageClient(this).sendMessage(node, START_ACTIVITY_PATH, new byte[0]); try { // Block on a task and get the result synchronously (because this is on a background // thread). Integer result = Tasks.await(sendMessageTask); LOGD(TAG, "Message sent: " + result); } catch (ExecutionException exception) { Log.e(TAG, "Task failed: " + exception); } catch (InterruptedException exception) { Log.e(TAG, "Interrupt occurred: " + exception); } }
@Override public void onPause() { super.onPause(); mDataItemGeneratorFuture.cancel(true /* mayInterruptIfRunning */); Wearable.getDataClient(this).removeListener(this); Wearable.getMessageClient(this).removeListener(this); Wearable.getCapabilityClient(this).removeListener(this); }
public void run() { //first get all the nodes, ie connected wearable devices. Task<List<Node>> nodeListTask = Wearable.getNodeClient(getApplicationContext()).getConnectedNodes(); try { // Block on a task and get the result synchronously (because this is on a background // thread). List<Node> nodes = Tasks.await(nodeListTask); //Now send the message to each device. for (Node node : nodes) { Task<Integer> sendMessageTask = Wearable.getMessageClient(MainActivity.this).sendMessage(node.getId(), path, message.getBytes()); try { // Block on a task and get the result synchronously (because this is on a background // thread). Integer result = Tasks.await(sendMessageTask); Log.v(TAG, "SendThread: message send to " + node.getDisplayName()); } catch (ExecutionException exception) { Log.e(TAG, "Task failed: " + exception); } catch (InterruptedException exception) { Log.e(TAG, "Interrupt occurred: " + exception); } } } catch (ExecutionException exception) { Log.e(TAG, "Task failed: " + exception); } catch (InterruptedException exception) { Log.e(TAG, "Interrupt occurred: " + exception); } } }
Wearable.getMessageClient(MainActivity.this).sendMessage(node.getId(), path, message.getBytes());
Wearable.getMessageClient(this).addListener(wearConsoleReceiver);