Demo code: github.com/.../
Some on-device apps may have complex external configuration requirements. I found an old thread discussing this:
Complex external configuration? - Discussion - Connect IQ - Garmin Forums
Quoting from that thread:
Default app settings is not user friendly for complex setups. For some kind of settings I have chosen the "config from elsewhere", thus my web app displays cleary all the possibilities but as said Jim it asks much work; a web app, a database to store settings, and a comunication watch->web app.
I want to share a trick which allows on-device apps to open an external configuration UI on a smartphone:
- Without an android companion app; only Connect IQ app
- Without a web service w/database storing user settings
This trick uses the OAuth APIs as a communication channel between the device and smartphone.
OAuth's intended purpose is to grant the device credentials to talk to a web service. However, when we break it down, here is what's actually happening:
- Device requests that Connect IQ open a webpage, including a data payload as query params
- Webpage sends a payload of data back to Connect IQ, which proxies it to the device
This means we have a bidirectional communication channel between the device and the phone, *without* installing a custom companion app on the smartphone.
- The device app calls makeOAuthRequest. The URL points to a static webpage w/JavaScript hosted on Github Pages or other static site host, with URL query params encoding all settings.
- The static webpage parses configuration from URL query params, presents an interactive UI to configure.
- When user clicks "Save," the webpage redirects to connectiq://oauth?<query params> with params encoding the modified settings.
- The app receives these params and updates settings accordingly.
Things I haven't tested yet:
- offline support: webpages actually don't require internet access if they declare a "cache manifest" Does this work with Connect IQ? Not sure yet
- Bidirectional serialization of Monkey C object <- base64 -> JavaScript. Can be reusable monkey C and JS libraries