0

I'm building a simple motivational quote app that generates a random quote from a MySQL database. The app works fine on mobile and I want to sync the quote message to a Wear device. I'm using MessageApi to do so and used this tutorial to set it up: http://android-wear-docs.readthedocs.org/en/latest/sync.html.

However, the message functionality only works when the app is running on the host device. I need to launch the app on Wear alone and still be able to receive the message from the mobile device. I thought of running the same application on the Wear device where it will run an httpconnection on it's own but from what I understand this is not possible with Android Wear.

So my question is, is there a way to open an app on a Wear device that will trigger the mobile app to open in the background and hence receive the message that way?

Iqen
  • 139
  • 1
  • 9

1 Answers1

0

Your mobile app can implement WearableListenerService. In that service implementation, you can listen to messages that are sent to your phone from your companion app on a wear device (when such message is sent to your phone, the framework on your phone starts up your service and passes the message to it). You can then implement the logic you need in that service (fetch a quote, etc) and respond back to your wear's message; when its work is done, that service will go away on its own. For this to work, your wear app needs to send such message to your phone app upon start up (or whenever you see appropriate in your app). This approach should work and probably is the most appropriate approach for your use case.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • Thanks, that makes sense and I'll give that a go. You mentioned that when the mobile starts up the service, it can do what I need to do (fetch a quote) and respond back to the wear's message. How do I respond back to the wear while within the mobile service where the Wear device can use that field and display it? – Iqen Nov 17 '15 at 18:13
  • From the message, you know which node had send the request, so you have the nodeId. In your service, you can create a GoogleApiClient for WearableApi, connect and then send the message. All of this is easily doable but if you are looking for even an easier solution, you can use the WearCompanionLibrary (https://github.com/googlesamples/android-WearCompanionLibrary) which can do most of these for you. – Ali Naddaf Nov 17 '15 at 18:29
  • Okay WearCompanionLibrary does look like an awesome tool that can do what I need easily. However I cant initialize and set it up for some reason. It doesn't seem to recognize when I try to declare the WearableListenerService in the manifest: ` ` – Iqen Nov 18 '15 at 03:09
  • How have you set up your dependencies? – Ali Naddaf Nov 18 '15 at 04:15