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?