On Friday afternoon a few people I know were talking about a web site for people who like to record their running and cycling and share it with their friends, the site is called dailymile. Dailymile allows you to upload GPS recordings of your routes so you can work out how far you’ve gone and also share routes with others.
Those of us that have Android phones tend to use an app called My Tracks to do the GPS recording and time our excursions. At the moment you either have to email the GPX files to yourself or if you have the Dropbox application installed, save them to the cloud storage before you can use dailymile’s web interface to upload them to the site.
Dailymile have recently published a REST API which includes an end point to upload new routes to, so it looked like it shouldn’t be too hard to put something together allow direct exporting of training sessions.
Getting something into the My Track’s “Share with Friends…” list is just a case of setting the right Intent Filter
<activity android:name=".Export" android:label="@string/app_name" android:exported="true"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/gpx+xml" /> </intent-filter> </activity>
I had already been playing with adding Account mangers to the Accounts & Sync section under the Android settings for a work project and this seamed like the best way to manage the OAuth requirements for the dailymile API. So I set about writing a SyncAdapter based on the previous code I already had. The problem is that dailymile have chosen to use OAuth 2.0 which is still a draft, so while there are a load of Java libraries out there that have support for 1.0 there are only a couple that have varying levels of support for different levels of draft for 2.0. The other problem is that there is no example on the dailymile api page of how to do OAuth authentication from a mobile app, which I’m starting to think means they’ve not implemented it yet.
curl -F grant_type=password -F client_id=[client_id] -F client_secret=[client_secret] -F username=[username] -F password=[password] https://api.dailymile.com/oauth/token
This gives the following output
So I’m wondering if this means that dailymile have to enable specific clients for this direct access to a token.
I’ve send a mail to the dailymile guys asking about this and if they can update their examples/docs for this case. In the mean time I’m going to have a look at using the web based authorization approach with a custom schema for the callback URL which I should be able to register with a suitable Intent filter.
<activity android:name=".AuthCallBackAct" android:label="@string/app_name" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="dm" android:host="localhost"/> </intent-filter> </activity>