Search code examples
androidwear-osandroid-wear-data-apiandroid-wear-2.0wearables

How do I get my own node_id for dataclient.getDataItem(Uri)?


In my project a wearos app communicates with a handheld mobile app using dataitems. My wearOS app sends data by placing and changing a data item in the data layer.

Before placing the item I want to load/get the item before potentially overwriting its content. I can recieve it using dataClient.getDataItems(). Yet to me this just seems not optimal, I wanna use dataClient.getDataItem(uri). In order to get the specific item I merely need the uri.

uri format: wear://<node_id>/<path>

The only thing I dont know is the node_id of my creator node. Through logging I have seen, that, even doe I create a new DataClient everytime, when I put a new item to data layer, the node id stays same. Yet I couldnt find a way to access the id.

I feel like there should be a simple function like getLocalNodeId() to get the missing uri part. Am I wrong?


Solution

  • No idear, why that took me so long to find:

     var node_id = Tasks.await(getNodeClient(context).localNode).id