--- layout: post status: publish published: true title: Mendeley Android Client Progress (w/ Video, Source and APK!) wordpress_id: 518 wordpress_url: http://www.martineve.com/?p=518 date: !binary |- MjAxMS0wMS0wNCAxOToxOTowMSArMDEwMA== date_gmt: !binary |- MjAxMS0wMS0wNCAxOToxOTowMSArMDEwMA== categories: - Technology - Android - PHP tags: - Android - Mendeley - Java comments: - id: 6064 author: Tweets that mention Mendeley Android Client Progress (w/ Video, Source and APK!) | Martin Paul Eve -- Topsy.com author_email: '' author_url: http://topsy.com/www.martineve.com/2011/01/04/mendeley-android-client-progress-w-video-source-and-apk/?utm_source=pingback&utm_campaign=L2 date: !binary |- MjAxMS0wMS0wNCAxOTo1MDozNiArMDEwMA== date_gmt: !binary |- MjAxMS0wMS0wNCAxOTo1MDozNiArMDEwMA== content: ! '[...] This post was mentioned on Twitter by Martin Eve, Martin Eve. Martin Eve said: New blog post: Mendeley Android Client Progress (w/ Video, Source and APK!) http://martineve.com/?p=518 #phdchat [...]' - id: 6113 author: Yasin Abbas author_email: yasin.abbas@eng.ox.ac.uk author_url: '' date: !binary |- MjAxMS0wMS0xNCAwNjoxMDowNyArMDEwMA== date_gmt: !binary |- MjAxMS0wMS0xNCAwNjoxMDowNyArMDEwMA== content: ! "Damn ... and there was a glimmer of excitement there ;]\r\n\r\n\r\nStill, glad someone's working on a client! Good luck with it Martin\r\n\r\n\r\nYaz" - id: 6144 author: Johannes author_email: mail@hehejo.de author_url: http://hehejo.de date: !binary |- MjAxMS0wMS0yNCAxNToyMToxOCArMDEwMA== date_gmt: !binary |- MjAxMS0wMS0yNCAxNToyMToxOCArMDEwMA== content: ! "Hi, I tried to use your app and it's failing at the oauth-step.\r\n\r\nDo you have a probably new APK somewhere?\r\n\r\nThanks and keep up with the good work,\r\nJohannes" - id: 6145 author: Martin Paul Eve author_email: martin@martineve.com author_url: '' date: !binary |- MjAxMS0wMS0yNCAxNTo0NDowNCArMDEwMA== date_gmt: !binary |- MjAxMS0wMS0yNCAxNTo0NDowNCArMDEwMA== content: ! "Hi, \n\nhoping to have a new release in a day or so." - id: 6264 author: Nick P author_email: perry1919@gmail.com author_url: '' date: !binary |- MjAxMS0wNC0wMSAwMDozNzowOCArMDIwMA== date_gmt: !binary |- MjAxMS0wNC0wMSAwMDozNzowOCArMDIwMA== content: ! "Hey, \n\nHave you made the app? I really want to use mendeley on my phone. I'll be getting a Nexus S here in 2-3 weeks and would love to put it on there :) \n\nThanks for all your hard work!" ---

Before anybody non-techie gets excited by the heading there, I'm not claiming this is anywhere near production-ready. In fact, it's not even functional. However, from a technical perspective, my Android Mendeley client has reached a milestone of succesful OAuth login. In this post I will give some samples of the application as it stands, including an APK download, source and video, and also detail the measures I undertook to get OAuth working using Signpost under Java for Android.

First up, there's now a Google Code project, which also includes GPL v3 licensed source code of my initial commit.

Secondly, here's a video of the client "in action" (running on the emulator):

Thirdly, if you felt the need to try out this "awesomeness" (read: currently useless fail) on your own device, you can download the apk and install it as an untrusted application.

As you can see, it successfully authenticates, but the API is throwing status 500 Internal Server errors on every API call at the moment. Whether this is a problem at their end, or mine, is unclear for now.

The Seriously Techie Bit

Finally, here's the technical explanation of things I tried, failed and then failed better at:

The first thing to note is that the latest version of signpost (1.2.1.1) will NOT work with Mendeley on Android. You'll certainly need 1.2. If you ignore this advice, you requests will all fail at provider.retrieveAccessToken.

Secondly, before calling provider.retrieveAccessToken you need to specify provider.setOAuth10a(true), or you will end up with a response telling you that there was no consumer key provided. Even though there was.

From MendeleyConnector.java:

{% highlight java %} m_provider.setOAuth10a(true); m_provider.retrieveAccessToken(m_consumer, code); {% endhighlight %}

Thirdly, as I mentioned in an earlier post, Mendeley will not allow you to perform a callback to any URL schema except http. For this reason, I have included a php script which must be placed on a webserver and simply performs a URL redirect when the oauth validation token is passed back in:

{% highlight php %} * * This file is part of Mendroid. * * Mendroid is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Mendroid is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Mendroid. If not, see . * */ if($_GET['oauth_verifier'] != "") { header( 'Location: martineve-mendroid:///?oauth_verifier=' . urlencode($_GET['oauth_verifier']) ) ; } ?> {% endhighlight %}

Ignore the signpost developers insistence on using the Apache Commons OAuthProvider/Consumer, they don't work whereas DefaultOAuthProvider works fine on signpost 1.2.

If anyone is interested in all the tweaks it took to get the 3 leg phase working, I suggest looking at MendeleyConnector.java (heavily modified from Clemens' version to do a direct callback into the application), but various calls are also in the related activities, MendeleyDroidLogin.java and the onResume function in MainScreenTabWidget (which handles the callback from the browser auth). The portion that is currently failing lies in MendeleyAPITask.java, which will eventually be used properly as an AsyncTask, but is for now just running as a synchronous call from the UI thread to make debugging easier.