Install in Android App

This guide describes integrating the Social Login feature only into your android App.

Prerequisites

1. Gather Configuration Details

Configure your desired set of social identity providers in the Dashboard. How tos are linked in the Identity Provider overview.

Retrieve your Application ID

Navigate to Home > Manage Engage app button >  Settings > App Info and record your Application ID.

2. Declare the Library Dependency

Configure your IDE with the library. Janrain provides guides for Eclipse and IntelliJ.

If you are using Apache Ant to build your project, use android update project -p path/to/your/prj -l path/to/jump.android/Jump.

3. Declare the Activities

Ensure the declaration of the android.permission.INTERNET permission in your <uses-permission> element, and copy from .../Jump/AndroidManifest.xml, adding the following two <activity> XML elements, and to your project’s AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />

  ...

  <application ... >

  ...

    <!-- The following activities are for the Janrain Engage for Android library -->
    <!-- This activity must have a dialog theme such as Theme.Holo.Dialog, or
        Theme.Dialog, etc.

        Using android:theme="@style/Theme.Janrain.Dialog" will result in Theme.Dialog on API 4-10 and
        Theme.Holo.DialogWhenLarge.NoActionBar on API 11+
    -->
    <activity
        android:name="com.janrain.android.engage.ui.JRFragmentHostActivity"
        android:configChanges="orientation|screenSize"
        android:theme="@style/Theme.Janrain.Dialog.Light"
        android:windowSoftInputMode="adjustResize|stateHidden"
        />

    <!-- This activity must have a normal (non-dialog) theme such as Theme, Theme.Light, Theme.Holo, etc.

        Using android:theme="@style/Theme.Janrain" or "@style/Theme.Janrain.Light" will result in
        Theme (or Theme.Light) on API 4-10 and
        Theme.Holo (or Theme.Holo.Light) on API 11+
    -->
    <activity
        android:name="com.janrain.android.engage.ui.JRFragmentHostActivity$Fullscreen"
        android:configChanges="orientation|screenSize"
        android:theme="@style/Theme.Janrain.Light"
        android:windowSoftInputMode="adjustResize|stateHidden"
        />

  ...

  </application>

</manifest>

Note: To target a version of Android lower than 13, change the android:targetSdkVersion, to your desired deployment target. You must still build against API 13+ even when targeting a lower API level. The build SDK used when compiling your project is defined by your project’s local.properties. android list target to get a list of targets available in your installation of the Android SDK. android update project -p path/to/project -t target_name_or_target_installation_id to update the build target SDK for your project. (Note that this does not affect your project’s minSdkVersion or targetSdkVersion.)

4. Import and Initialize

Import the following classes:

import com.janrain.android.engage.JREngage;
import com.janrain.android.engage.JREngageDelegate;
import com.janrain.android.engage.JREngageError;
import com.janrain.android.engage.net.async.HttpResponseHeaders;
import com.janrain.android.engage.types.JRActivityObject;
import com.janrain.android.engage.types.JRDictionary;

Interaction begins by calling the JREngage.initInstance method, which returns the JREngage object:

private static final String ENGAGE_APP_ID = "";
private static final String ENGAGE_TOKEN_URL = "";
private JREngage mEngage;
private JREngageDelegate mEngageDelegate = ...;

...

mEngage = JREngage.initInstance(this.getApplicationContext(), ENGAGE_APP_ID, ENGAGE_TOKEN_URL, this);

initInstance takes four arguments, context, appId, tokenUrl, and delegate:

Choosing your Delegate Class

Select a class you will use to receive callbacks from the library. This is called your delegate. The delegate should be a singleton object. A good place to start is your app’s Android Application class, if you have one. Activities which are always at the root of the back stack can be acceptable choices. Avoid using Activities which will short lived.

5. Social Login

A Social Login authentication is meaningful in the context of authenticating your mobile app to something. If you are unsure of what your users should be authenticating to, then Janrain User Registration solution may be a great choice. This signs authenticating users into your copy of their social profile, affording your mobile app a place to store and retrieve data from, and a pier from which to build out a service.

Once the JREngage object has been initialized, start authentication by calling showAuthenticationDialog method:

mEngage.showAuthenticationDialog();

You will receive your authentication token URL’s response in the jrAuthenticationDidReachTokenUrl method. When received you will have access to the body of the response, as well as the headers, which frequently contain session cookies used to coordinate the app’s session with your web server. Parsing your authentication token URL’s response for session establishing information, or retrieving session cookies from the header, is your app’s responsibility.

For guidance implementing your web-server’s authentication token URL, see Authentication-Token-URL.md.