Monday, 21 January 2019

OnCapabilityChanged working on phone but not on wearable

After carefully following the instructions in this post:

How to detect when android wear device gets disconnected? I finally managed to get my phone to detect when the wearable is connected using onCapabilityChanged.

I have followed the exact same steps on the wearable side and I am trying to detect when the phone is connected to the wearable but onCapabilityChanged is never triggered.

wear.xml (on the phone)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="android_wear_capabilities">
        <item>track_phone</item>
    </string-array>
</resources>

In AndroidManifest (wearable)

<service android:name=".BackgroundService.WearableService"
            android:enabled="true"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
                <data android:scheme="wear" android:host="*"/>
            </intent-filter>
        </service>

In WearableService (on wearable)

override fun onCapabilityChanged(p0: CapabilityInfo?) {
    super.onCapabilityChanged(p0)
    Log.i("WearableService", "Capability changed: {${p0?.nodes?.size ?: "null"}")
}

I am sure the service is started as I have another process running from it

I am doing the same thing on the phone side. When I dissconnect/connect the bluetooth onCapabilityChanged is correctly called in the phone's service, but not on the wearable's service.

Any ideas?



from OnCapabilityChanged working on phone but not on wearable

No comments:

Post a Comment