Skip to content Skip to sidebar Skip to footer

Android Wear - Gradle Dependency Issues "cannot Resolve Symbol"

I followed the instructions here to build a simple app with mobile and wear components in Android Studio. I have the following code in my mobile activity, trying to call MyWearActi

Solution 1:

You should instead use the MessageAPI to send a message to your Wear device. You can learn how to do so here: https://developer.android.com/training/wearables/data-layer/index.html and here is an example (assuming you've already created and connected a GoogleApiClient)

privatevoidfireMessage(final String message) {
    // Send the RPC
    PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(apiClient);
    nodes.setResultCallback(newResultCallback<NodeApi.GetConnectedNodesResult>() {
        @OverridepublicvoidonResult(NodeApi.GetConnectedNodesResult result) {
            for (inti=0; i < result.getNodes().size(); i++) {
                Nodenode= result.getNodes().get(i);
                StringnName= node.getDisplayName();
                StringnId= node.getId();
                Log.d(TAG, "Node name and ID: " + nName + " | " + nId);

                PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(apiClient, node.getId(),
                        message, null);
                messageResult.setResultCallback(newResultCallback<MessageApi.SendMessageResult>() {
                    @OverridepublicvoidonResult(MessageApi.SendMessageResult sendMessageResult) {
                        Statusstatus= sendMessageResult.getStatus();
                        Log.d(TAG, "Status: " + status.toString() + " Msg: " + message);
                        if (status.getStatusCode() != WearableStatusCodes.SUCCESS) {
                            //alertButton.setProgress(-1);
                            Toast.makeText(getApplicationContext(), "Tap to retry. Alert not sent :(", Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        }
    });
}

Then, in your wear module, you should implement a listener, or better yet, a WearableListenerService with an onMessageReceived method to respond to that message. For example, you could have that service fire an intent based on the message to start an Activity, or build a notification to display on the device. Here is a guide to building notifications https://developer.android.com/training/wearables/notifications/index.html

Solution 2:

No, think of the Wear module and the Mobile module as two completely different apks or apps (because they are). You do not directly call to the activities in the Wear module from the Mobile app. The wear app is started through user interaction. What exactly are you trying to do?

Ok, based on your comment below, the problem is still that you can't call a WearActivity from the Mobile app since that is in a different library/app that is not linked together. The example code from above in the answer from Nickjm is a good start.

Post a Comment for "Android Wear - Gradle Dependency Issues "cannot Resolve Symbol""