Android Guidelines |

Getting Started with Android SDK Integration

You can get started with the following:

The latest version of InMobi SDK supports Android OS versions 4.0.3 (API level 15) and later.

Version 6.2.4
Size (.APK Inflation) 342 KB
SDK Links

Adding the SDK to your Project

Method 1: Pulling the latest SDK via jCenter

If you are using Gradle to build your Android applications, you can pull the latest version of the SDK from jCenter.

To do so:

  1. Include this in your top-level build.gradle file:
    allprojects {
        repositories {
            jcenter()
        }
    }
    			
  2. Add the following line to the dependencies element in your application module’s build.gradle.
    compile 'com.inmobi.monetization:inmobi-ads:6.X.X'
    			
  3. Sync your Gradle project to ensure that the dependency is downloaded by the build system.

Method 2: Adding the SDK library to your application project

Alternately, you can download the latest version of InMobi’s SDK here and copy the library to your application module’s libs/ directory.

To add the library to your project’s dependencies, add this line to the dependencies element in your module’s build.gradle.

compile fileTree(dir: 'libs', include: ['*.jar'])
		

Adding and Verifying the Dependencies

To monetize with the InMobi ad SDK, you must add the following dependencies:

  • Google Play Services

    The InMobi SDK for Android needs the Google Play Services library to enable better ad targeting via the Google Play Advertising ID. Additionally, the SDK also uses the Google Play Services for getting a location fix, should the User consent to collecting location.

    To add the Google Play Services client library to your application:

    1. Add the following line to the application module’s dependency element.
      compile 'com.google.android.gms:play-services:8.4.0'
      				
    2. Sync your Gradle project to ensure that the dependencies are included.
    3. Add the following element to your application manifest.
      <meta-data android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
      				
  • Picasso

    The InMobi SDK for Android uses the popular Picasso library for loading the ad assets.

    To add the Picasso library to your application:

    1. Add the following line to the application module’s dependency element in the Gradle build script.
      compile 'com.squareup.picasso:picasso:2.5.2'
      				
    2. Sync your Gradle project to ensure that the dependencies are included.
    3. Note: Failure to include Picasso dependency in your application gradle scripts will cause interstitial ad requests to fail, thus affecting monetization of your app with the InMobi SDK.
  • Support Library

    For the Native Storyboards ad format, you must add the support-v4 library.

    To do so, add the following line to the application module’s dependency element in the Gradle build script.

    compile 'com.android.support:appcompat-v7:24.0.0'
    			
  • RecyclerView

    For supporting free scroll of a deck of images or ads, you must use use RecyclerView.

    To do so, add the following line to the application module’s dependency element in the Gradle build script.

    compile 'com.android.support:recyclerview-v7:24.0.0'
    			

    Note: Failure to include RecyclerView dependency in your application gradle scripts will cause interstitial ad requests to fail, thus affecting monetization of your app with the InMobi SDK.

  • Miscellaneous

    At times, including the InMobi SDK may cause the 64K limit on methods that can be packaged in an Android dex file to be breached. For example, this can happen if your app packs a lot of features for your users and includes substantive code to realize this. If this happens, you can use the multidex support library to enable building your app correctly.

    To do this:

    1. Modify the defaultConfig to mark your application as multidex enabled:
      defaultConfig {
      applicationId "com.inmobi.samples"
      minSdkVersion 15
      targetSdkVersion 24
      versionCode 1
      versionName "1.0.0"
      multiDexEnabled true // add this to enable multi-dex
      }
      				
    2. Add the following line to the dependencies element in your application module’s build script.
      compile 'com.android.support:multidex:1.0.1'
      				

Changing the Manifest File

Granting Permissions

You must include the following mandatory permissions in your application manifest.

Note: Failure to include these permissions will affect your ability to monetize your application on the InMobi network.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
		

In addition to the mandatory permissions above, it is highly recommended that you include either the ACCESS_COARSE_LOCATION or the ACCESS_FINE_LOCATION to enable better ad targeting. This is not a mandatory permission; however, including it will enable accurate ad targeting.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
		

For further improved targeting, you can add the ACCESS_WIFI_STATE and the CHANGE_WIFI_STATE permissions to the manifest.

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
		

If you are requesting for rich-media ads, you can add the following permissions.

<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
		

Showing Full-screen Ad Overlays

For ads that open a full screen overlay, you must include the following activity element in your application manifest.

<activity
android:name="com.inmobi.rendering.InMobiAdActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
android:hardwareAccelerated="true"
android:resizeableActivity="false"
android:theme="@android:style/Theme.NoTitleBar"
tools:ignore="UnusedAttribute" />
		

Attribution of App Installs

Mandatory permission:

For attribution of app installs, add the following in the manifest file:

<receiver
     android:name="com.inmobi.commons.core.utilities.uid.ImIdShareBroadCastReceiver"
     android:enabled="true"
     android:exported="true"
     tools:ignore="ExportedReceiver">
          <intent-filter>
              <action android:name="com.inmobi.share.id"/>
          </intent-filter>
 </receiver>
		

Hardware Acceleration

Hardware acceleration allows you to display HTML5 video ads. To do this, add hardwareAccelerated:true element to the application tag.

Proguard Configuration

Proguarding helps to remove unused symbols and reduce the final application footprint. The following proguard directives should be added to your application’s proguard configuration file.

-keepattributes SourceFile,LineNumberTable
-keep class com.inmobi.** { *; }
-dontwarn com.inmobi.**
-keep public class com.google.android.gms.**
-dontwarn com.google.android.gms.**
-dontwarn com.squareup.picasso.**
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient{
     public *;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info{
     public *;
}
# skip the Picasso library classes
-keep class com.squareup.picasso.** {*;}
-dontwarn com.squareup.picasso.**
-dontwarn com.squareup.okhttp.**
# skip Moat classes
-keep class com.moat.** {*;}
-dontwarn com.moat.**
# skip AVID classes
-keep class com.integralads.avid.library.* {*;}
		

Preparing your App for Android N

InMobi SDK is compatible with Android N (API level 24), the latest version of the Android platform. You can start monetizing on Android N with minimal changes to your application manifest.

Declare the InMobiAdActivity element in your application like so if your app is targeting API level 24 or higher.

<activity
    android:name="com.inmobi.rendering.InMobiAdActivity"
    android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
    android:hardwareAccelerated="true"
    android:resizeableActivity="false"
    android:theme="@android:style/Theme.NoTitleBar"
    tools:ignore="UnusedAttribute" />
		

In particular, note the android:resizeableActivity=”false” attribute and configuring this activity for screenLayout changes.

Initializing the SDK

  1. Initialize the SDK in your launcher Activity like so, by passing in the Activity context and your InMobi account ID.
    InMobiSdk.init(MainActivity.this, "Insert InMobi Account ID here");
    			

    Find your account id from your account interface as shown in the image below.

    Note: You must call this method on the UI thread. Not doing so will cause the initialization to fail and affect your application’s ability to monetize with InMobi.

  2. Pass location signals to allow better ad targeting.

    Recommended: If your app collects location from the user, we recommend passing it up, as impressions with location signal have higher revenue potential. InMobi SDK will automatically pass the location signals if available in the app. If you use location in your app, but would like to disable passing location signals to InMobi, then TURN OFF the “Location Automation” for your property on the InMobi dashboard.

    Otherwise: You can pass the location signals as follows:

    InMobiSdk.setLocation(locationObj);
    			

    Alternately, you can set the city, state and country as well:

    InMobiSdk.setLocationWithCityStateCountry(“city”,“state”,“country”);
    			
  3. Pass demographic signals to allow better ad targeting.

    You can supply the InMobi SDK with the gender and age:

    InMobiSdk.setGender(InMobiSdk.Gender.MALE); // or InMobiSdk.Gender.FEMALE
        InMobiSdk.setAge(age); 
        InMobiSdk.setAgeGroup(InMobiSdk.AgeGroup.BELOW_18); 
    // other enums: BETWEEN_18_AND_20, BETWEEN_21_AND_24, BETWEEN_25_AND_34 
    // BETWEEN_35_AND_5, ABOVE_55
    			

Note: Pass location signals to allow better ad targeting.

Start monetizing your Android app with these ad formats: