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 7.1.1
Size (.APK Inflation) 370 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:7.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-base:11.8.0'    
          compile 'com.google.android.gms:play-services-ads:11.8.0'
          compile 'com.google.android.gms:play-services-location:11.8.0'
          compile 'com.google.android.gms:play-services-plus:11.8.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 supporting paged scroll of a deck of images or ads, you must use 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:support-v4:27.1.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:27.1.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

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.

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="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	

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 O (API level 26), the latest version of the Android platform.

Version N onwards, Android has introduced the ability to support connections exclusively over HTTPS. Though InMobi is committed towards the adoption of HTTPS, the current setup requires our demand partners to support this change. Therefore, we recommend the publishers to maintain the default settings OFF as it can have an impact on the revenue potential.

Initializing the SDK

  1. Initialize the SDK, using one of the two init APIs provided below in your launcher, by passing in the Activity context and your InMobi account ID.
                JSONObject consentObject = new JSONObject();
    try {
       // Provide correct consent value to sdk which is obtained by User
       consentObject.put(InMobiSdk.IM_GDPR_CONSENT_AVAILABLE, true);
      // Provide 0 if GDPR is not applicable and 1 if applicable 
       consentObject.put("gdpr", "0");
    } catch (JSONException e) {
       e.printStackTrace();
    }
    InMobiSdk.init(this, "Insert InMobi Account ID here", consentObject);
    		
    1. consentObject - A consentObject is a JSONObject representation of all kind of consent provided by the publisher to the SDK. The key is mandatory if you wish to monetize traffic from EEA region. InMobi relies on publishers to obtain user consent to comply with the regulations. You can read further on GDPR regulations here.
      Key Type Inference
      gdpr_consent_available boolean "true" - Publisher has provided consent to collect and use user’s data.

      "false" - Publisher has not provided consent to collect and use user’s data.

      Any value other than “true” and “false” is invalid and will be treated as value not provided by publisher, i.e. empty value.

      gdpr Number Whether or not the request is subjected to GDPR regulations, deviation from the set values (0 = No, 1 = Yes ), indicate an unknown entity.

      The key gdpr_consent_available can be accessed via string constant IM_GDPR_CONSENT_AVAILABLE

      Important

      1. You need to provide consentObject in every session. The SDK does not persist consent, it only keeps the consentObject in memory. If the app is relaunched or crashes - SDK will lose the consentObject.
      2. Within a session, you can update the consent like this:
        InMobiSdk.updateGDPRConsent(JSONObject consentObject)
        				
      3. As part of the General Data Protection Regulation (“GDPR”) publishers who collect data on their apps, are required to have a legal basis for collecting and processing the personal data of users in the European Economic Area (“EEA”). Please ensure that you obtain appropriate consent from the user before making ad requests to InMobi for Europe and indicate the same by following our recommended SDK implementation. Please do not pass any demographics information of a user; if you do not have user consent from such user in Europe.
    2. Find your account ID from the 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.

    InMobi relies on the publishers to obtain explicit consent from user for continuing business activities in EU as per GDPR .

    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_24, BETWEEN_25_AND_29, BETWEEN_30_AND_34 
    // BETWEEN_35_AND_44, BETWEEN_45_AND_54, BETWEEN_55_AND_65, ABOVE_55
    		

Note: Pass location signals to allow better ad targeting.

Start monetizing your Android app with these ad formats: