Search code examples
androidwear-os

Android: check if wear app is installed on paired watch


I have two android apps(mobile/watch), and I want to check on the mobile app if the wear app is installed on the watch or not.

Any thoughts?

I searched but no results.


Solution

  • It's described in Detect your app on another device, there is also a sample in Github.

    In a nutshell, you should:

    1. Add res/values/wear.xml file to your watch module, specifying your app's capability:
    <resources xmlns:tools="http://schemas.android.com/tools"
            tools:keep="@array/android_wear_capabilities">
        <string-array name="android_wear_capabilities">
            <item>your_custom_app_capability</item>
        </string-array>
    </resources>
    
    1. On the phone app, add a listener to CapabilityClient:
            val capabilityClient = Wearable.getCapabilityClient(this)
    
            capabilityClient.addListener({ capabilityInfo -> {
                // the watch with the wear app that contains
                // your custom capability can be retrieved from:
                capabilityInfo.nodes
            } }, "your_custom_app_capability")