Android LinkedIn Authentication made me want to Tear My Hair and Poke My Eyes Out

Apparently there exists is no single working full Android project in the google-able universe that demonstrates authentication via LinkedIn or Google completely functionally. I’m very good at finding things, and have been unsuccessful at finding a project I can import that Just Works. Even now we don’t have one, but I’ll share the following that finally got me to a working authentication.

  1. Take the Menu creation and launch of Login with separate WebViewActivity from the “Android” section from here: https://sites.google.com/site/oauthgoog/oauth-practices/mobile-apps-for-complex-login-systems/samplecode
  2. If you don’t yet know how to create a separate Activity, learn how to do that here: http://stackoverflow.com/questions/3690851/android-creating-a-new-activity-in-eclipse
  3. Replace the  Step 1 Menu code for onOptionItemSelected, Login action item, from Step 1 with the browser launching code from the COMMENTS section of this page: http://code.google.com/p/linkedin-j/wiki/AndroidConfiguration
  4. Fix the typo in the COMMENT, replacing
    public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin";
    with
    public static final String OAUTH_CALLBACK_SCHEME = "x-oauth-linkedin";

    5. Finally,

    To resolve “Commuication with service provider failed” :

    Add to your MAIN activity’s onCreate() method:

    if (android.os.Build.VERSION.SDK_INT > 9) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);
    }

    Details explained here: http://stackoverflow.com/questions/8706464/defaulthttpclient-to-androidhttpclient

    Of course you know you need to get your API key, right? That’s googlable.

Leave a Reply