Getting Started with Android SDK

Requirements

Android 4.0 (Ice Cream Sandwich) and above.

Installing the SDK

Maven

To install the Neumob SDK through Maven, add the following to your pom.xml between the <dependencies>…</dependencies> tags:

<dependency>
    <groupId>com.neumob</groupId>
    <artifactId>neumob-android</artifactId>
    <version>LATEST</version>
 </dependency>

Gradle

To install the Neumob SDK through Gradle, add the following compile line to your dependencies in your application build.gradle file (under project_name/app directory).

dependencies {
    ...
    compile 'com.neumob:neumob-android:3.2.8'
}

Manual installation

1. Download the Neumob JAR file on the portal page. You can find under a download link under your App settings.

../_images/android_portal_sdk_download.png
  1. Copy the Neumob JAR file to your libs folder

3a. (Eclipse only) Right click your project, click Properties and select Java Build Path, click Add External Jar, and then add the Neumob JAR file. 3b. (Android Studio) Right click the jar file and click Add as library.

4. (Eclipse only) You must make the following changes in the Eclipse IDE in order to perform builds directly from Eclipse. On the Eclipse menu bar, go to ADT -> Preferences -> Android -> Build, uncheck the option Force error when external jars contain native libraries.

Setting up the Manifest

For full functionality with Neumob, you will need to add the following permissions to your AndroidManifest.xml file.

  • INTERNET - Required
  • ACCESS_NETWORK_STATE - Required, allows Neumob to determine optimal mobile configurations
  • ACCESS_WIFI_STATE - Required, allows Neumob to update mobile configurations based on network changes
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Initializing Neumob

Initialization is the process of modifying your application in order to communicate with Neumob. Initialize Neumob only once on the main thread at the beginning of your onCreate activity.

Neumob.initialize(getApplicationContext(),“NEUMOB_CLIENT_KEY");

If you are adding the Neumob import manually, use

import com.neumob.api.Neumob;

Neumob is now integrated with your Android application! If you are using an Android 3rd party networking libraries like OkHttp, please find the integration guide for your library under the Android menu. In order to turn ON Neumob for your app version you’ll go to the portal’s app details page where you received your client key. The State for the app version will be OFF and this can be changed by clicking the settings button under Action, toggling the switch in the upper right corner of the following screen, and then the Apply button at the bottom.

Note

Neumob takes about 2 days to learn, customize, and then accelerate you network calls.

Verifying Integration

To check that Neumob is initialized and whether an app session is being accelerated, you can add a Runnable parameter that will execute after initialize is completed. Because init can be asynchronous, checking isAccelerated and related API outside of the Runnable may return inconsistent values.

isInitialized returns a boolean indicating Neumob is enabled and ready to accelerate your network requests.

isAccelerated returns a boolean indicating whether Neumob is currently accelerating your requests. You may configure whether or not Neumob is accelerated by adjusting the % accelerated slider through the portal (click the settings button for the app version on your app details page). If you plan to A / B test accelerated vs unaccelerated Neumob users, we recommend using the isAccelerated API in the Runnable. Please note that isAccelerated is sticky- meaning a user who is accelerated will remain accelerated until the % accelerated slider value is changed.

The isAccelerated boolean value can be used to populate a property or dimension within your mobile analytics platform.

Here’s an example of how you might verify Neumob initialization and check whether a session is accelerated.

Neumob.initialize(getApplicationContext(),“NEUMOB_CLIENT_KEY", new Runnable() {
     @Override
     public void run() {
         if (Neumob.isInitialized()) {
             // Neumob is ON.
             boolean isAccelerated = Neumob.isAccelerated();
             // ex. Analytics.logCustomDimension(Dimension.ACCELERATION, isAccelerated);
             ...
         } else {
             // Neumob is OFF. Change log settings for more details.
             ...
         }
     }
});

Note

We do not recommend executing your own initialization code inside the runnable block. Also note that the runnable is not executed on the UI thread.

Disabling Neumob

If for any reason you are looking to disable Neumob, navigate to the portal to your app settings and select the combination of application versions and/or Neumob SDK versions that should be enabled. Once disabled, Neumob will not initialize on the client device.

../_images/disable_neumob.png

Compatibility

The Neumob Android SDK has been verified with the following Android libraries:

  • OkHttp
  • Volley
  • VolleyPlus
  • Retrofit
  • Glide
  • Universal Image Loader
  • Picasso
  • Fresco

Considerations

1. The Neumob Android SDK uses the ProxySelector class. If you require setting your own default version you may consider waiting for support in the near future.

2. If you use 3rd party libraries like Google Analytics, we recommend adding those hosts to your a customizable blacklist you can find by navigating to your application on the portal.

3. For future versions if Neumob is not being updated properly while developing on Android studio try reinstalling as the jni libraries may cached.

  1. Blacklist / Whitelisting will not work for Android WebView