Search code examples
androidwear-oswear-os-tiles

How to send data from main app to tile on wear os?


Quick and direct question: How do I send data from the main application to a tile on wear os? It is a simple data to be send, for example a "foo" string Ps. Unless there isnt another way, I rather not having any action from the user, like a "get" button...

SharedPreferences does not seem to work... I dont want to create a database for just one line of data... But if there is no option, ok.

I'm new to wear os development, so I still dont know much about it. Thank you for ur help


Solution

  • You'll need to write to some sort of cache. You can't rely on your app being running between fetching the data and the tile updating.

    So write to something like SharedPreferences, or ProtoDataStore, PreferencesDataStore.

    Then send a tile update

    TileService.getUpdater(applicationContext).requestUpdate(RememberWearTileProviderService::class.java)
    

    And in your tile, read from the same data source.