Android Wearable.API is deprecated. What should i use instead?

I am using the following:

GoogleApiClient mApiClient = new GoogleApiClient.Builder(this) .addApi( Wearable.API ) ... 

So how is Wearable.API deprecated? What is the appropriate replacement?

+5
source share
1 answer

I found something nice that is useful

 private class StartWearableActivityTask extends AsyncTask<Void, Void, Void> { final String key; public StartWearableActivityTask(String msg){ key = msg; } @Override protected Void doInBackground(Void... args) { Collection<String> nodes = getNodes(); for (String node : nodes) { sendStartActivityMessage(node,key); } return null; } } @WorkerThread private Collection<String> getNodes() { HashSet<String> results = new HashSet<>(); 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); for (Node node : nodes) { results.add(node.getId()); } } catch (ExecutionException exception) { Log.e(TAG, "Task failed: " + exception); } catch (InterruptedException exception) { Log.e(TAG, "Interrupt occurred: " + exception); } return results; } @WorkerThread private void sendStartActivityMessage(String node,String event) { Task<Integer> sendMessageTask = Wearable.getMessageClient(this).sendMessage(node, event, 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); } catch (ExecutionException exception) { Log.e(TAG, "Task failed: " + exception); } catch (InterruptedException exception) { Log.e(TAG, "Interrupt occurred: " + exception); } } 
0
source

Source: https://habr.com/ru/post/1274506/


All Articles