androidbluetoothandroid-jetpack-composewear-oswearables

Is there a way to show an OS-level icon in my Wear OS app, when the watch is disconnected from the phone?


I have seen that in Apple watches, when the watch has been disconnected from the iPhone, in the watch apps, there is an icon in the top center that shows that the watch has been disconnected.

Is there anything similar in Wear OS?

Some kind of OS level icon that can be implemented easily, similar to how I could use TimeText() in Compose to show the OS time without having to handle it myself?

Or is my only option to use the Bluetooth manager to check for connections, and show a custom icon myself based on that?

I tried putting my Wear OS device on airplane mode. This shows a disconnection icon in the watch face. I would like to show that icon in the app. There seems to be no official documentation on this topic, so perhaps it is not possible?


Solution

  • No OS level facility. Instead of using the BluetoothManager, you can subscribe to the NetworkManager, and then show whether you are connected to the paired mobile, or possibly have a Wifi/LTE network.

            val networkRequest = NetworkRequest.Builder()
                .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
                .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
                .addTransportType(NetworkCapabilities.TRANSPORT_BLUETOOTH)
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .build()
            connectivityManager.registerNetworkCallback(networkRequest, networkCallback)
    

    The TimeText component is extensible, so you can add leading content like is done here.

    https://github.com/google/horologist/blob/fe6ee111501b05fbd1d33dd1bdd9fe87333c4477/network-awareness/src/main/java/com/google/android/horologist/networks/ui/DataUsageTimeText.kt#L4