Start an Android service from watch

Hi everyone,

I'm sure I just overlooked something, but I can't find any clues on how to intercept a message from watch as an intent.
Other watches such as Android Wear or Pebble both have an app intercepting any messages and distributing the corresponding intents.

E.g. on Pebble, all messages from watch go to the Pebble app. When the Pebble application receives a message from a watch application, it broadcasts an intent with action “com.getpebble.action.app.RECEIVE“, and ‘extra’ data containing the message content.

I couldn't find anything like that in the CIQ SDK, although there is also a Garmin Connect Mobile app that could theoretically do this.

What I want to do is to start my Android service (via a Broadcast intent receiver) whenever my CIQ app sends a message to the phone.

Is there a way to do that?
  • I have thought about using
    Communications.openWebPage("myscheme://myurl",null,null);
    and listen to it, but it seems that GCM filters out all URLs with non-standard schemes (I have tried only http).
    Also the openWebPage only gives out a notification and doesn't open the URL directly.
  • Former Member
    Former Member over 8 years ago
    On Android Garmin Connect Mobile processes all of the incoming data from watch but if you use Communications.transmit in your app, then it's possible to listen for these events in custom Android application and do something, that GCM is unable to or does in different way that you expect. To find out how to listen for watch events sent by transmit statement, look through MobileSDK guide, "Receiving messages" section, namely "registerForAppEvents" function.
    For example, it's possible to create background service, which will listen for watch messages, do something complex on receive and send feedback back to watch.
  • AHEAD centre

    Sorry for being unclear on the background of my question.

    I am aware of the standard way of direct BLE communication using the Communications module on watch side and "registerForAppEvents" on the phone side, as documented in the MobileSDK guide. I have this already implemented in my app and I am fine with that.

    What I am not fine with is that for communication to occur, I have to start both the Android app and the watch app. Isn't there a way to start app on either watch or phone from the other device?
    I have a motion tracking app on the watch, and it is not very convenient to have a service running on the phone for the whole time just to have the CIQ SDK ready for listening....this will probably drain the battery a lot, not to say how it will interact with the numerous battery savers that are ubiquitous nowadays...

    If this is not possible and any CIQ team member reads this, please take it as a very important suggestion for the next GCM release...
  • Thank you for replying.

    I am well aware of the standard way of doing direct BLE comm as documented in the MobileSDK guide, and have this implemented in my app without any issues.
    I have my Android service as you suggest, but this cannot be running the whole time just waiting for the user to start the watch app, since there will be battery drain issues, not to mention issues with the numerous battery savers that are ubiquitous on Android nowadays.
    I want to start the Android service when my watch app starts.
    The question is, how do I start the Android service by the IQ app, without having the ConnectIQ SDK previously initialized.

    Are there any intents that GCM emits when receiving messages from the watch that I could listen to?

    You see, this is a huge oversight on the CIQ part -- for any communication to occur, you must start both the phone and the watch apps. On every other smartwatch (Android Wear, Pebble, Samsung Gear ...) you don't have to do this.

    If this is not possible, and an CIQ team member reads this, please take it as a very important suggestion for the next GCM release....
    Uses are numerous, for example:
    - starting turn-by-turn navigation when user starts navigation on phone
    - starting sleep tracking on phone when user starts sleep tracking app on watch (my case)
    - using watch sensors on demand by phone apps (e.g. on-demand heart rate measurement, or using watch accelerometer for games)
    - lots of others, you probably know much better than me...

    You will unlock the developer's potential with this, and now is the right time because all of the devs coming from Pebble to Garmin...
  • Former Member
    Former Member over 8 years ago
    I agree, that letting service run in background is not the most efficient way to handle watch calls battery wise, in Android Wear we have WearableListenerService for this, which is actually a receiver contrary to it's name, but I doubt that this techinque will be implemented in GCM soon enough: just look at the GCM's power consumption.

    As for the other thing you mentioned: they would be nice, of course, but looking on how timely watch-phone communication related bugs are fixed (e.g. a rather obvious fatal error, which was caused by an updated parcel structure in GCM messages was in development for about two months) I once again doubt, that they will be implemented at all, because seems like currently smartwatch scenario is not considered a priority by Garmin (at least mobile) team. Thus, if you're looking to invest your time into development of this kind of applications, be aware of the possible (and sometimes impenetrable) hindrancies.

    I cannot blame Garmin for that, because smartwatches went (almost) large not long ago and most of the hardware developers (except maybe big players like Tag) are still in doubt whether this kind of wearables will actually become popular.
    I like mine FR230 and I wrote a handful of apps for it already: some of them I use myself, some - release to public, but I'm still looking for that one perfect sport/smart watch...
  • Many thanks for your insight easuvorov...

    I am quite a newcomer to CIQ, but I felt that the CIQ development team is gaining momentum, since to my taste the SDK updates are quite frequent and they are adding new features, generally moving the right direction (for example adding the intents (however half-baked) or optimizing messaging). Also finally adding a bug tracking to this forum also feels as if the CIQ team might devote more time to the devs...
    Maybe I am overoptimistic as I was used to Pebble's approach, but to me, it feels a little similar with the Garmin guys...but maybe it's just the 'cool' terminology in the SDK docs that makes me sympathise :)
  • Take a look at my post here: https://forums.garmin.com/showthread.php?366342-Tasker-Integration . Using autonotification you can intercept the openwebpage() notifications and dismiss them and then run a custom tasker task. I can publish an update to my app that works for more than just the forerunner 235 if interested.
  • Many thanks CTHIELKER.

    This looks like a nice workaround, but you still have to have some service running - which in this case is the tasker/autonotification, isn't it?
    Unfortunately I cannot make the user of my app use tasker & autonotification.
    However this all depends on how the autonotification works. Is there any broadcast intent sent when a notification arrives? Is the Tasker/autonotification a service or a Broadcast receiver?
  • Tasker is an android app for automation. AutoNotification is a plugin. I have updated the app today to allow support of most devices, not all 100% tested. It allows you to run 3 "tasks" using buttons and a menu that lets you pick up to 20 more tasks that you can run.
  • Sorry for not being clear again, for the second time on this thread :)

    I know Tasker well, so I don't have problem with grasping the concept.
    But it isn't really a solution in this case, since if you have to run the Tasker and Autonotification (and I believe Tasker just runs a service all the time to be able to intercept the notification), you can run your own service as well to intercept the direct messaging.

    But I may be mistaken -- if the Autonotification works in a Broadcast receiver manner, i.e. it intercepts some hypothethical broadcast intent which is sent by Android when a notification from GCM is shown, then it may be possible to dump the Tasker/Autonotification altogether, and create my own IntentService/Broadcast receiver that would intercept the notification on its own.

    I have to dig into the Android docs....or do you know whether there is any broadcast sent when the GCM notification shows up? What exactly does the Autonotif listen to?