简体   繁体   中英

Getting Data To Android Wear Without Opening Companion App

I'm attempting to add some functionality to our current app's offering by implementing a custom app on Android Wear.

In an ideal use case I would like to have the user open the wear app and for it to ask the handheld for the current data that it has stored. My first thought was to use an IntentService, but it does not appear that I'm able to get this to work with an implicit Intent. Also, after reading the data syncing section it appears that this is not the preferred manner of getting data for a wearable.

I've read over the Data Layer and Syncing section of the Wear docs. It seems to me that in order to get data syncing to occur between the handheld and wearable that the companion app on must be opened first on the handheld, data sync occurs between the GoogleApiClient, the wear app is opened, the wear app receives the data from the GoogleApiClient.

Does the above flow work? From my reading it seem like this happens in semi real time where the companion app and wear app were open at the same time. If the user closes the companion app on the handheld and then later opens the wear app will the data be there or will the push only occur if both activities are active?

So, is this a design constraint for the wearable model by Google, such that the companion app must have pushed the data before the wearable can request it? Also, repeating my second question, can the companion app close after it has pushed the data and the wearable retrieve the data at another time even if the companion app is not running?

The companion app doesn't have to be opened at all.

I have a wearable app where the companion app simply is a service that extends WearableListenerService and performs all the heavy-duty network functions, and passes everything back to the wearable app via the data layer.

It has no UI and is not launchable on the handheld device. It is solely a proxy for the wearable app. It doesn't have a single Activity.

Synching occurs under the hood and I do not have to worry about it. I believe that is Google's intention.

In an ideal use case I would like to have the user open the wear app and for it to ask the handheld for the current data that it has stored.

Implement a WearableListenerService in your existing app, it will listen for requests from the wear app. In your wear app onCreate send a message via the data layer. Continue the messaging conversation in the service on your existing app. You will need a listener in the wear app too of course.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM