0

I'm developing an Android Application with a Watch module (applicationID is the same for the app and watch). I'm testing the communication with a real device and a watch emulator, but since last day no message arrive in WearableListenerService and I don't understand why.

This is my Service (app device) in manifest

<service
        android:name=".receivers.PhoneMessageService"
        android:enabled="true"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
            <data
                android:host="*"
                android:scheme="wear" />
        </intent-filter>
    </service>

The app Listener

class PhoneMessageService : WearableListenerService() {

override fun onMessageReceived(message: MessageEvent?)
{
    message?.let { msg ->
        sendActionToReceiver(msg.path, msg)
    }
}

With this method I get the nodes (i always getthe node of my phone, infact nodes is always size 1):

 private fun getNodes(context: Context, mode: WearCommunicationMode, callback: ((Node?) -> Unit))
{
    val capability = Wearable.getCapabilityClient(context).getCapability(mode.capabilityKey, CapabilityClient.FILTER_REACHABLE)
    capability.addOnSuccessListener { task ->
        val nodes = task?.nodes
        if(nodes != null && nodes.size > 0) {
            val bestNodeID = nodes.find { node -> node.isNearby } ?: nodes.first()
            callback.invoke(bestNodeID)
        }else{
            callback.invoke(null)
        }
    }
}

Nodes size is 1, so I'm connected with device, but onMessageReceived isnt't called anymore... what I'm doing wrong?

1 Answer 1

0
<service
    android:name=".receivers.PhoneMessageService"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
        <data
            android:host="*"
            android:scheme="wear" />
    </intent-filter>
</service>

exported needs to be true!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.