androidwear-osandroid-wear-data-api

Android Wear Data Layer API working only one time


I use the Data Layer API to send commands from my wearable to my handheld. This all worked fine until this afternoon. I changed nothing in my code but suddenly only the first command after the handheld-App is restarted works. All following commands are sent at the wearable but not received at the handheld. I went through all of it with breakpoints and did two times the same thing but only the first time it worked.

Code of wearable:

public void run() {
            Task<List<Node>> nodeListTask = Wearable.getNodeClient(getApplicationContext()).getConnectedNodes();
            try {
                List<Node> nodes = Tasks.await(nodeListTask);
                for (Node node : nodes) {

                    Task<Integer> sendMessageTask = Wearable.getMessageClient(MainActivity.this).sendMessage(node.getId(), "/wear_control", TextUtils.join(";", slices).getBytes());
                    Integer result = Tasks.await(sendMessageTask);
                }
            } catch (Exception exception) {
                exception.printStackTrace();
                //TODO aaaaaaaaaaaaaaaaaa
            }
            slices.clear();
        }

Code from handheld (in a foreground service):

@Override
    public void onMessageReceived(MessageEvent messageEvent) {
        if (messageEvent.getPath().equals("/wear_control")) {
            ProcessMessage.evaluate(new String(messageEvent.getData()), this);
        }
        else {
            super.onMessageReceived(messageEvent);
        }
    }

But as I said, I changed nothing at the code, but it doesn't work anymore.

Thanks in advance.


Solution

  • After some debugging I discovered that the shell code I used had a process.waitFor(). This stopped the application from doing like anything after one shell command was executed. So nothing wrong with the data layer.