Reputation: 27221
<service android:name=".SMessage">
<intent-filter>
<action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:host="*" android:pathPrefix="/send-message" android:scheme="wear" />
</intent-filter>
</service>
public class SMessage extends WearableListenerService {
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
super.onCapabilityChanged(capabilityInfo);
_A.toast("onCapabilityChanged");
Set<Node> connectedNodes = capabilityInfo.getNodes();
pickBestNodeId(connectedNodes);
}
}
this method is not fired onCapabilityChanged
if I enable aircraft mode or disable bluetooth connection.
What have I missed?
_A.toast
shows toast using Application class.
Sending messages works.!
Upvotes: 1
Views: 506
Reputation: 6635
You need to include an android:path
element that identifies the (fully-qualified) capability you're listening for:
<intent-filter>
<action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
<data android:host="*" android:scheme="wear"
android:path="/com.mypackagename.my_capability_name"/>
</intent-filter>
where my_capability_name
is defined in the wear.xml
of your app running on the other device:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="android_wear_capabilities">
<item>my_capability_name</item>
</string-array>
</resources>
as documented at https://developer.android.com/training/wearables/data-layer/messages.html#AdvertiseCapabilities.
A couple of caveats, however:
Upvotes: 3