I am trying to write a companion app to push a Play Store link from phone to wear OS watch to install my watch face. I have this function that is called when a button is pressed. It is supposed to get the nodeID for the wear OS device and push the link to the wear OS device. When I put my phone in Wireless Debugging mode with Android Studio and run the app on the my phone (which is connected to my watch), the button appears responsive, and the toast messages display, but nothing happens on my watch. I added a toast message to display the nodeID and it returns as “null,” leading me to believe the portion of code that is supposed to retrieve the nodeID is not working. There are no errors in Android Studio. Can anyone help me figure out why this code is not successfully getting the nodeID?
@Composable
fun InstallButton() {
val context = LocalContext.current
OutlinedButton(onClick = {
context.sendLink()
}) {
Text("Install on Watch")
}
}
fun Context.sendLink() {
var watchNode: Node? = null
val uri: String = [package uri]
// Creates a thread
Thread {
// Get all nodes (nodes are devices connected)
val nodeListTask: Task<List<Node>> =
Wearable.getNodeClient(applicationContext).connectedNodes
try {
// Try to get the first node and assign it to the watchNode variable
watchNode = Tasks.await(nodeListTask)[0]
} catch (ignore: Exception) {
}
}.start()
Toast.makeText(this, "NodeID: " + watchNode, Toast.LENGTH_SHORT).show()
...more code for RemoteActivityHelper....}