Android

Prerequisites

  • The latest version of InMobi Mediation SDK supports Android 4.2.2 (Jelly Bean, API 17) and higher. Additionally, MRAID ads require API 19 and higher.

    Note

    Older Android versions may work but are not officially supported.

  • Google Play Services will adhere to the user’s ad tracking preferences. For more information, please see Google's website regarding their Advertising ID.
  • We recommend calling all InMobi Mediation APIs on UiThread.

Now that you have ensured these requirements, let's look at some checkpoints before we integrate the SDK:

Checkpoint 1: Preparing Your App for Android 10

InMobi SDK is compatible with Android 10 (API level 29), the latest version of the Android platform. From Android P onwards, apps make connections over HTTPS by default. Though InMobi supports the adoption of HTTPS, the current setup requires our demand partners to support HTTPS as well. The publisher can change their settings to HTTP if it has an impact on the revenue potential.

Checkpoint 2: Preparing Your App for AndroidX

InMobi SDK is compatible with AndroidX (JetPack) library. In case your app uses the AndroidX library, then follow the standard guidelines by Google for migration by adding both the flags in build file.

android.useAndroidX=true
android.enableJetifier=true

It is highly recommended to upgrade the Android Gradle plugin version to 4.1 or greater to avoid known issues in the jetifier which is fixed in the latest Gradle plugin version. To upgrade the Android Gradle plugin version please refer to Android developer documentation.

Step 1: Integrating the SDK

  • Step 1.1: Adding the InMobi SDK to your Project

    Option 1: Pulling the Latest SDK via mavenCentral

    If you are using Gradle to build your Android applications, you can pull the latest version of the SDK from mavenCentral as described below:

    1. Include mavenCentral in your top-level build.gradle file:

      allprojects {
          repositories {
              mavenCentral()
          }
      }
      
    2. Add the following line to the dependencies element in your application module’s build.gradle file.

      implementation 'com.inmobi.monetization:inmobi-ads:9.1.9'
      implementation 'com.inmobi.monetization:inmobi-mediation:9.1.9'
      
    3. Sync your Gradle project to ensure that the dependency is downloaded by the build system.

    Option 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:

    implementation fileTree(dir: 'libs', include: ['*.aar'])
    
  • Step 1.2: Adding and Verifying the Dependencies

    To monetize with the InMobi Mediation SDK, you must add the following dependencies to your app module build.gradle. For more information on why each dependency is required, see below:

    android {
      defaultConfig {
      }
      buildTypes {
        ...
      }
      sourceSets {
        main {
        }
      }
    }
    repositories {
      ...
    }
    dependencies {
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0' //optional dependency for better targeting
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    }
    
    • 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 Google Play Services for getting a location fix, should the user consent to collecting their location.

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

      1. Add the following line to the application module’s dependency element.

        implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
        implementation 'com.google.android.gms:play-services-location:17.0.0' //optional dependency for better targeting
        
      2. Sync your Gradle project to ensure that the dependencies are included.
    • Chrome Custom Tab

      This is required to redirect the users to URLs outside InMobi WebView:

      To add the Chrome Custom library to your application:

      1. Add the following line to the application module's dependency element in the Gradle build script:

        implementation 'com.android.support:customtabs:28.0.0'
        
      2. Sync your Gradle project to ensure dependencies are included.

      Note

      Failure to include Chrome Custom Tab dependency in your application Gradle scripts will cause ad requests to fail, thus affecting the monetization of your app with the InMobi SDK.

    • Picasso Library

      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:

        implementation 'com.squareup.picasso:picasso:2.71828'
        
      2. Sync your Gradle project to ensure that the dependencies are included.

      Note

      Failure to include Picasso dependency in your application Gradle scripts will cause interstitial ad requests to fail, thus affecting the 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.

      implementation 'com.android.support:support-v4:28.0.0'
      
    • RecyclerView

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

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

      implementation 'com.android.support:recyclerview-v7:28.0.0'
      
       

      Note

      Failure to include RecyclerView dependency in your application Gradle scripts will cause interstitial ad requests to fail, thus affecting the 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. This can happen if, for example, 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 29
                    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.

        implementation 'com.android.support:multidex:1.0.3'
        

Note

Now that you have added the dependencies, your app's build.gradle at this point will look like as shown below:

  • Step 1.2a: Additional Configurations

    Granting Permissions

    It is highly recommended that you include ACCESS_FINE_LOCATION to enable better ad targeting. This is not mandatory permission; however, including it will enable accurate ad targeting.

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

    For further improved targeting, you can add the ACCESS_WIFI_STATE and 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"></uses-permission></uses-permission>
    
     

    Hardware Acceleration

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

    <application ...="" android:hardwareaccelerated="true"></application>
    
  • Step 1.3: 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.** { *; }
    -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.okhttp.**
    # skip Moat classes
    -keep class com.moat.** {*;}
    -dontwarn com.moat.**
    # skip IAB classes
    -keep class com.iab.** {*;}
    -dontwarn com.iab.**
    
  • Step 1.4: Android Manifest

    • Add the following Android permission and activities into your Android Manifest:

      <!--?xml version='1.0' encoding='utf-8'?-->
      <manifest package="com.sample.myapp" xmlns:android="http://schemas.android.com/apk/res/android">
      <!-- Optional Permissions -->
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
      <application android:allowbackup="true" android:label="@string/app_name">
      </application>
      </uses-permission></uses-permission></uses-permission></manifest>
      
       

      Note

      Not including the optional permission MAY negatively impact fill for the respective networks that use these permissions.

Step 2: Initialize the SDK

  • You must initialize SDK before loading any ads.We recommend that you invoke the initialization routine and wait for the completion callback before you intend to show your first ad. We suggest you initialize the SDK during the onCreate() state within your main activity. Failure in the initialization of SDK will cause every ad request to timeout as initialization is mandatory.
  • To initialize the SDK, invoke AerServSdk.init(activity, siteId, gdprConsentObject, sdkInitializatonListener) on the AerServSdk class.
  • To set or update the General Data Protection Regulation (GDPR) user consent flag, you can either call AerServSDK’s setGdprConsent method or pass it through the initialization method.

    What is a 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 European Economic Area; 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 String A consent string is a series of numbers, which identifies the consent status of an Ad-tech Vendor.

    The string must follow the IAB contracts as mentioned here.

    The key, gdpr_consent can be accessed via string constant IM_GDPR_CONSENT_IAB.

    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 a value not provided by the publisher, i.e. empty value.

    The key gdpr_consent_available can be accessed via string constant IM_GDPR_CONSENT_AVAILABLE.

    gdpr String Whether or not the request is subjected to GDPR regulations, deviation from the set values (0 = No, 1 = Yes ), indicates an unknown entity.
/**
* Start "pre-init". Returns error object with an appropriate message when SDK was
* not successfully initialized, otherwise null.
*
* @param context  Context
* @param siteId   AerServ's "siteID" or "appId"
* @param listener Represents a listener object to provide callback when SDK initialization
*                 process is complete
*/
public static void init(@NonNull final Context context,
                        @NonNull final String siteId,
                        @Nullable SdkInitializationListener listener)
/**
* Start "pre-init". Returns error object with an appropriate message when SDK was
* not successfully initialized, otherwise null
*
* @param context           Context
* @param siteId            AerServ's "siteID" or "appId"
* @param gdprConsentObject User consent for GDPR
* @param listener          Represents a listener object to provide callback when SDK
*                          initialization process is complete
*/
public static void init(@NonNull final Context context,
                        @NonNull final String siteId,
                        @Nullable final JSONObject gdprConsentObject,
                        @Nullable final SdkInitializationListener listener)
/**
* Set the flag for user consent.
*
* @param gdprConsentObject Users' consent for GDPR.
*/
public static void setGdprConsent(@Nullable JSONObject gdprConsentObject);
/**
* Returns the consent flag for GDPR
* @param context Context. This is left in for legacy reason. Pre-unification, the AS stored the
*                consentFlag inside the SharedPreferences. This meant we needed the context. At
*                the same time, we don't want to remove this parameter for publisher already
*                integrated with the older API.
* @return Returns the flag for user consent in GDPR
*/
@Nullable
public static Boolean getGdprConsentFlag(@NonNull Context context);

How to obtain the app ID:

  • Log in to the AerServ + InMobi platform.
  • Go to the 'Inventory' tab in the top navigation bar.
  • Click the 'Edit' icon next to the app whose ID you wish to obtain.
  • You will find the app ID at the very top of the page.

Mediation Disclaimer

Please be advised that although we are GDPR compliant, we currently have no way to send GDPR compliance as well as user consent to our mediated SDK partners. Compliance responsibility and request handling will solely depend on the SDK mediated partner. Please contact your mediated partners to avoid any issues and/or complications.

Step 3: Displaying Banner Ads

  • Create an instance of the AerServBanner object. One way of doing this is to define it in your Activity's layout file, e.g. activity_main.xml. The following example will create a 320x50 banner within the MainActivity:

    <com.aerserv.sdk.aerservbanner android:id="@+id/banner" android:layout_height="50dp" android:layout_width="320dp"></com.aerserv.sdk.aerservbanner>
    
  • In your code, obtain a reference to the AerServBanner instance and use it to call configure() and show().

    package com.sample.myapp;
    import android.app.Activity;
    import android.os.Bundle;
    import com.aerserv.sdk.AerServBanner;
    import com.aerserv.sdk.AerServConfig;
    import com.aerserv.sdk.AerServSdk;
    public class MainActivity extends Activity {
      private static final String APP_ID = "1000473";
      private static final String PLACEMENT_ID = "1024876";
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                @Override
                public void onInitializationComplete(@Nullable Error error) {
                    if (null != error) {
                        Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                    } else {
                        Log.d(TAG, "AerServ Init Successful");
                    }
                }
            });
      }
      /**
       * The banner doesn't need to be loaded in the main activity. However, the context that's passed
       * in must also be a activity context.
       */
      public void loadBannerAd() {
        AerServConfig config = new AerServConfig(this, PLACEMENT_ID);
        /**
         * After finding the view, you'll have to typecast the view into a AerServBanner object;
         */
        banner = (AerServBanner) findViewById(R.id.banner);
        /**
         * If you are not preloading, you MUST call show right after configure is called. Failing to do
         * so will result in unintended behavior.
         */
        banner.configure(config).show();
      }
    }
     
  • Alternatively, you can also create the AerServ Banner instance programmatically.

    package com.sample.myapp;
    import android.app.Activity;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.util.TypedValue;
    import android.view.ViewGroup;
    import android.widget.RelativeLayout;
    import com.aerserv.sdk.AerServBanner;
    import com.aerserv.sdk.AerServConfig;
    public class MainActivity extends Acitvity {
      private static final String APP_ID = "1000473";
      private static final String PLACEMENT_ID = "1024876";
      private AerServBanner banner;
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                @Override
                public void onInitializationComplete(@Nullable Error error) {
                    if (null != error) {
                        Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                    } else {
                        Log.d(TAG, "AerServ Init Successful");
                    }
                }
            });
      }
      /**
      * AerServBanner is a subclass of the RelativeLayout class and can be modify as such.
      * (e.g.RelativeLayout.setLayoutParams to change the width and height of the view)
      */
      public void loadBannerAd() {
        AerServConfig config = new AerServConfig(this, PLACEMENT_ID);
        banner = new AerServBanner(this);
        /**
         * Setting the height and width of the banner. This was previously done in the xml.
         */
        Resources r = getResources();
        float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 320, r.getDisplayMetrics());
        float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, r.getDisplayMetrics());
        banner.setLayoutParams(new RelativeLayout.LayoutParams(Math.round(width), Math.round(height)));
        /**
         * Add the banner as a child view. You MUST add the view into the UI before calling configure
         * and show. In this example, we'll be adding it to the root view group.
         */
        ((ViewGroup) findViewById(android.R.id.content)).addView(banner);
        banner.configure(config).show();
      }
    }
    
     

    If you’d like your app to listen to ad events and know when an ad has loaded or failed, implement an AerServEventListener and add it to your AerServConfig object:

    package com.sample.myapp;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import java.util.List;
    import com.aerserv.sdk.AerServBanner;
    import com.aerserv.sdk.AerServConfig;
    import com.aerserv.sdk.AerServEvent;
    import com.aerserv.sdk.AerServEventListener;
    import com.aerserv.sdk.AerServSdk;
    public class MainActivity extends Acitivity {
      private static final String APP_ID = "1000473";
      private static final String PLACEMENT_ID = "1024876";
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                @Override
                public void onInitializationComplete(@Nullable Error error) {
                    if (null != error) {
                        Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                    } else {
                        Log.d(TAG, "AerServ Init Successful");
                    }
                }
            });
      }
      public void loadBannerAd() {
        AerServEventListener listener = new AerServEventListener() {
          @Override
          public void onAerServEvent(AerServEvent event, List params) {
            switch (event) {
              case AD_LOADED:
                // Execute some code when AD_LOADED event occurs.
                break;
              case AD_DISMISSED:
                // Execute some code when AD_DISMISSED event occurs.
                break;
              case AD_FAILED:
                // Execute some code when AD_FAILED event occurs.
                break;
            }
          }
        };
        AerServConfig config = new AerServConfig(this, PLACEMENT_ID);
        /**
        * You'll have to pass the AerServEventListener through the the AerServConfig.
        */
        config.setEventListener(listener);
        AerServbanner banner = (AerServBanner) findViewById(R.id.banner);
        banner.configure(config).show();
      }
    } 

For additional events, please see Additional Settings section.

  • You should pause your banner when your app is backgrounded, and play it when the app resumes. You can also kill a banner.

    The methods are:

    package com.sample.myapp;
    import android.app.Activity;
    import android.os.Bundle;
    import com.aerserv.sdk.AerServBanner;
    import com.aerserv.sdk.AerServConfig;
    import com.aerserv.sdk.AerServSdk;
    public class MainActivity extends Activity {
      private static final String APP_ID = "1000473";
      private static final String PLACEMENT_ID = "1024876";
      private AerServBanner banner = null;
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                @Override
                public void onInitializationComplete(@Nullable Error error) {
                    if (null != error) {
                        Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                    } else {
                        Log.d(TAG, "AerServ Init Successful");
                    }
                }
            });
      }
      /**
       * You will want to call pause when the banner goes out of view. One example of this occurring is
       * when the activity goes into the pause state, it prevents the banner from refreshing in the
       * background. This will occur when you switch the intent to another activity or when the
       * application goes into the background.
       */
      @Override
      public void onPause() {
        if(banner != null) {
          banner.pause();
        }
      }
      /**
       * Once the activity resumes and the banner is in view again, you can resume the banner refresh.
       */
      @Override
      public void onResume() {
        if(banner != null) {
          banner.play();
        }
      }
      /**
       * Once the activity is about to be destroyed, you'll want to call kill on the banner object to
       * to ensure that all resources is cleaned.
       */
      @Override
      public void onDestroy() {
        if(banner != null) {
          banner.kill();
        }
      }
      public void loadBannerAd() {
        // The PLC 1024876 is for testing only and returns a 320x50 static HTML banner
        AerServConfig config = new AerServConfig(this, PLACEMENT_ID);
        AerServBanner banner = (AerServBanner) findViewById(R.id.banner);
        banner.configure(config).show();
      }
    } 
    
  • Pausing a banner will prevent it from refreshing, and killing it will remove it from the view.

Step 4: Display Interstitial Ads

You can configure and show a test interstitial ad in your Activity, as follows:

package com.sample.myapp;
import android.app.Activity;
import android.os.Bundle;
import com.aerserv.sdk.AerServSdk;
import com.aerserv.sdk.AerServConfig;
import com.aerserv.sdk.AerServInterstitial;
public class MainActivity extends Activity {
  private static final String APP_ID = "1000473";
  private static final String PLACEMENT_ID = "1000741";
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
            @Override
            public void onInitializationComplete(@Nullable Error error) {
                if (null != error) {
                    Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                } else {
                    Log.d(TAG, "AerServ Init Successful");
                }
            }
        });
  }
  public void loadInterstitialAd() {
      AerServConfig config = new AerServConfig(this, PLACEMENT_ID);
      AerServInterstitial interstitial = new AerServInterstitial(config);
      interstitial.show();
  }
]

If you’d like your app to listen to ad events and know when an ad has loaded or failed, implement an AerServEventListener and add it to your AerServConfig object:

package com.sample.myapp;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import java.util.List;
import com.aerserv.sdk.AerServConfig;
import com.aerserv.sdk.AerServEvent;
import com.aerserv.sdk.AerServEventListener;
import com.aerserv.sdk.AerServInterstitial;
import com.aerserv.sdk.AerServSdk;
public class MainActivity extends Acitivity {
  private static final String APP_ID = "1000473";
  private static final String PLACEMENT_ID = "1000741";
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
            @Override
            public void onInitializationComplete(@Nullable Error error) {
                if (null != error) {
                    Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                } else {
                    Log.d(TAG, "AerServ Init Successful");
                }
            }
        });
  }
  public void loadInterstitialAd() {
    AerServEventListener listener = new AerServEventListener() {
      @Override
      public void onAerServEvent(AerServEvent event, List params) {
        switch (event) {
          case AD_LOADED:
            // Execute some code when AD_LOADED event occurs.
            break;
          case AD_DISMISSED:
            // Execute some code when AD_DISMISSED event occurs.
            break;
          case AD_FAILED:
            // Execute some code when AD_FAILED event occurs.
            break;
        }
      }
    };
    AerServConfig config = new AerServConfig(this, PLACEMENT_ID);
    /**
     * You'll have to pass the AerServEventListener through the the AerServConfig.
     */
    config.setEventListener(listener);
    AerServInterstitial interstitial = new AerServInterstitial(config);
    interstitial.show();
  }
}
 
  • For additional events, please see Additional Settings section.
  • Preloading will start the process of fetching an ad and caching the video. It also informs the app earlier whether it will get an ad. We highly recommend that you use this feature whenever possible.

    To preload an interstitial ad, the steps are:

    1. Create an AerServEventListener listener and listen to the PRELOAD_READY event. When the event is fired, the ad is successfully preloaded.
    2. Create an AerServConfig object, and set the above AerServEventListener as listener. Set preload flag to true in above AerServConfig object.
    3. Instantiate an AerServInterstitial object, which will start the preload process. Do NOT call show() yet, as the ad is still being loaded. When you are ready to show the ad, call show(). You must only call show after you have received PRELOAD_READY event in step 1 above.

    Here is the code snippet for the above steps:

    package com.sample.myapp;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import java.util.List;
    import com.aerserv.sdk.AerServConfig;
    import com.aerserv.sdk.AerServEvent;
    import com.aerserv.sdk.AerServEventListener;
    import com.aerserv.sdk.AerServInterstitial;
    import com.aerserv.sdk.AerServSdk;
    public class MainActivity extends Activity {
      private static final String APP_ID = "1000473";
      private static final String PLACEMENT_ID = "1000741";
      private AerServInterstitial interstitial = null;
      private bool isAdLoaded = false;
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                @Override
                public void onInitializationComplete(@Nullable Error error) {
                    if (null != error) {
                        Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                    } else {
                        Log.d(TAG, "AerServ Init Successful");
                    }
                }
            });
      }
      /**
       * We check if the preload flag has been previously set. This is so that we don't waste an ad that
       * has already been preloaded and calling another load won't necessary fill.
       */
      public void loadInterstitialAd() {
          if(isAdLoaded == false) {
            AerServEventListener listener = new AerServEventListener() {
              @Override
              public void onAerServEvent(AerServEvent event, List params) {
                switch (event) {
                  case PRELOAD_READY:
                    MainActivity.this.isAdLoaded = true;
                    // Anywhere after this point you can call showInterstitial();
                    break;
                  case AD_DISMISSED:
                    MainActivity.this.isAdLoaded = false;
                    Log.v(MainActivity.class.getSimpleName(), "Interstitial was shown.");
                    break;
                  case AD_FAILED:
                    MainActivity.this.isAdLoaded = false;
                    Log.v(MainActivity.class.getSimpleName(), "Interstitial failed to load.");
                    break;
                }
              }
            };
            AerServConfig config = new AerServConfig(this, PLACEMENT_ID)
              .setEventListener(listener)
              .setPreload(true); // This flag needs to be set for preload to work correctly.
            interstitial = new AerServInterstitial(config);
          } else {
            Log.v(MainActivity.class.getSimpleName(), "Interstitial has already been loaded");
          }
      }
      public void showInterstitial() {
        if(interstitial != null && isAdLoaded) {
          interstitial.show();
        } else {
          Log.v(MainActivity.class.getSimpleName(), "Interstitial has not been loaded");
        }
      }
    }
     

Step 5: Additional Settings

  • Complete List of Events

    • Our SDK fires these additional AerServEvent events that can be caught by AerServEventListener:

    EVENT CALLBACK ENUM PURPOSE
    AD_CLICKED Ad was clicked or touched
    AD_COMPLETED Ad has completed
    AD_DISMISSED Ad has been closed
    AD_FAILED Ad failed to load
    AD_IMPRESSION Ad has shown
    LOAD_TRANSACTION This event will return a BuyerName as well as a BuyerPrice for the loaded ad.
    AD_LOADED Ad has been loaded
    PRELOAD_READY Ad has been preloaded
    VC_READY This event communicates the Virtual Currency (VC) name, amount, buyer name, and buyer price of the loaded ad. Please note that it does not imply the ad is preloaded nor does it imply that VC is rewarded. For those, you need to listen to PRELOAD_READY and VC_REWARDED events, respectively.
    VC_REWARDED Virtual Currency was rewarded
    VIDEO_COMPLETED Video has completed
    VIDEO_START Video ad has started
    SHOW_TRANSACTION This event communicates the Transaction Information of the loaded ad. This includes the buyer name and buyer price.
  • Virtual Currency

    • Virtual Currency (VC) allows you to reward users based on completed video views. You can configure the VC name and amount on SSUI, and the SDK will inform your app via events when the user has fully watched a video.
    • Here is the code example of how to listen to VC events:

      package com.sample.myapp;
      import android.app.Activity;
      import android.os.Bundle;
      import android.util.Log;
      import java.utils.List;
      import com.aerserv.sdk.AerServConfig;
      import com.aerserv.sdk.AerServEvents;
      import com.aerserv.sdk.AerServEventListener;
      import com.aerserv.sdk.AerServInterstitial;
      import com.aerserv.sdk.AerServVirtualCurrency;
      public class MainActivity extends Activity {
        private static final String APP_ID = "1000473";
        private static final String PLACEMENT_ID = "1000741";
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                  @Override
                  public void onInitializationComplete(@Nullable Error error) {
                      if (null != error) {
                          Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                      } else {
                          Log.d(TAG, "AerServ Init Successful");
                      }
                  }
              });
        }
        public loadInterstitialAd() {
          AerServEventListener listener = new AerServEventListener() {
            @Override
            public void onAerServEvent(AerServEvent event, List params) {
              switch (event) {
                /**
                 * The VC_READY event will notify when we load the creative. Note that you can also get
                 * the buyerName and buyer price throught the LOAD_TRANSACTION and SHOW_TRANSACTION event.
                 */
                case VC_READY:
                  AerServVirtualCurrency vc = (AerServVirtualCurrency) params.get(0);
                  String name = vc.getName();
                  BigDecimal amount = vc.getAmount();
                  String buyerName = vc.getBuyerName();
                  BigDecimal buyerPrice = vc.getBuyerPrice();
                  // Add your logic here 
                  break;
                /**
                 * The second callback will notify when the virtual currency has been rewarded. This will
                 * only fire after the user has watch 100% of the video on a virtual currency enable
                 * placement.
                 */
                case VC_REWARDED:
                  AerServVirtualCurrency vc = (AerServVirtualCurrency) params.get(0);
                  String name = vc.getName();
                  BigDecimal amount = vc.getAmount();
                  String buyerName = vc.getBuyerName();
                  BigDecimal buyerPrice = vc.getBuyerPrice();
                  // Add your logic here 
                  break;
              }
            }
          };
          /**
           * Nothing change when using either of these AerServEvent. Both VC_READY and VC_REWARDED will
           * work with banners and interstitial integration.
           */
          AerServConfig config = new AerServConfig(this, PLACEMENT_ID)
            .setEventListener(listener)
          AerServInterstitial interstitial = new AerServInterstitial(config);
          interstitial.show();
        }
      }
       

      Note

      The buyer name and buyer price can be null, so if you intend to use those objects, make sure you check for a null value.

      • Use AerServConfig object to set user ID:

        String USER_ID = "MyUserId";
        String PLACEMENT_ID = "1000741";
        AerServConfig config = new AerServConfig(MainActivity.this, PLACEMENT_ID).setUserId(USER_ID);
         
      • We also support server VC callbacks. To use this feature please see the How to Set Up Rewarded Currency (Virtual Currency).The userId is required for VC enabled placements to be used on the server VC callback and for frequency capping.

        The userId is required for VC enabled placements to be used on the server VC callback and for frequency capping.

    • Ad Transaction Information

      During the process of showing an ad, the InMobi SDK will additionally return information pertaining to the buyer for your ad space and the price that the ad space was bought for.

      This detailed information can be found from these events:

      package com.sample.myapp;
      import android.app.Activity;
      import android.os.Bundle;
      import java.util.List;
      import com.aerserv.sdk.AerServConfig;
      import com.aerserv.sdk.AerServEvent;
      import com.aerserv.sdk.AerServEventListener;
      import com.aerserv.sdk.AerServInterstitial;
      import com.aerserv.sdk.AerServSdk;
      import com.aerserv.sdk.AerServTransactionInformation;
      public class MainActivity extend Activity {
        private static final String APP_ID = "1000473";
        private static final String PLACEMENT_ID = "1000741";
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                  @Override
                  public void onInitializationComplete(@Nullable Error error) {
                      if (null != error) {
                          Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                      } else {
                          Log.d(TAG, "AerServ Init Successful");
                      }
                  }
              });
        }
        public void loadInterstitialAd() {
          AerServEventListener listener = new AerServEventListener() {
            @Override
            public void onAerServEvent(AerServEvent event, List params) {
              switch (event) {
                /**
                 * The LOAD_TRANSACTION event will contain the transaction information of the ad from the
                 * first load attempt. The transaction information from this callback may be different
                 * from the ad the produce the impression.
                 */
                case LOAD_TRANSACTION:
                    AerServTransactionInformation vc = (AerServTransactionInformation) params.get(0);
                    String buyerName = vc.getBuyerName();
                    BigDecimal buyerPrice = vc.getBuyerPrice();
                    // Add your logic here 
                    break;
                /**
                 * The didShowAdWithTransactionInfo callback will cotanin the transaction information of
                 * the ad that produced a impression. 
                 */
                case SHOW_TRANSACTION:
                    AerServTransactionInformation vc = (AerServTransactionInformation) params.get(0);
                    String buyerName = vc.getBuyerName();
                    BigDecimal buyerPrice = vc.getBuyerPrice();
                    // Add your logic here 
                    break;
              }
            }
          };
          /**
           * Nothing change with this implementation. Both LOAD_TRANSACTION and SHOW_TRANSACTION will work
           * with banners and interstitial integration.
           */
          AerServConfig config = new AerServConfig(this, PLACEMENT_ID)
            .setEventListener(listener)
          AerServInterstitial interstitial = new AerServInterstitial(config);
          interstitial.show();
        }
      }
      
    • Adding Publisher Keys

      Custom revenue reports can be generated via the SDK by assigning a dictionary object with publisher key value pairs to the pubKeys property. This is available for both interstitials and banners.

      package com.sample.myapp;
      import android.app.Activity;
      import android.os.Bundle;
      import java.util.HashMap;
      import java.util.Map;
      import com.aerserv.sdk.AerServConfig;
      import com.aerserv.sdk.AerServInterstitial;
      import com.aerserv.sdk.AerServSdk;
      public class MainActivity extends Activity {
        private static final String APP_ID = "1000473";
        private static final String PLACEMENT_ID = "1000741";
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                  @Override
                  public void onInitializationComplete(@Nullable Error error) {
                      if (null != error) {
                          Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                      } else {
                          Log.d(TAG, "AerServ Init Successful");
                      }
                  }
              });
        }
        public void loadInterstitialAd() {
          Map<string, string=""> pubkeys = new HashMap();
          pubkeys.put("key", "value");
          AerServConfig config = new AerServConfig(this, PLACEMENT_ID)
                  .setPubKeys(pubkeys); // Pass in the Map object.
          interstitial = new AerServInterstitial(config);
          interstitial.show();
        }
      }</string,>
       

      For details about publisher keys, click here.

    • Enabling the Back Button(not supported in InMobi SDK 8.0.1)

      Enable the back button for interstitial. When the user clicks on the back button, the interstitial will exit. This is similar to when skip is enabled on the AerServ + InMobi dashboard. This will only work for ads coming from AerMarket, S2S or tags. By default, the backbutton is only enabled when the a becomes skippable.

      package com.sample.myapp;
      import android.app.Activity;
      import android.os.Bundle;
      import com.aerserv.sdk.AerServConfig;
      import com.aerserv.sdk.AerServInterstitial;
      import com.aerserv.sdk.AerServSdk;
      public class MainActivity extends Activity {
        private static final String APP_ID = "1000473";
        private static final String PLACEMENT_ID = "1000741";
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          AerServSdk.init(this, APP_ID,new SdkInitializationListener() {
                  @Override
                  public void onInitializationComplete(@Nullable Error error) {
                      if (null != error) {
                          Log.e(TAG, "AerServ Init Failed with error message: " + error.getMessage());
                      } else {
                          Log.d(TAG, "AerServ Init Successful");
                      }
                  }
              });
        }
        public void loadInterstitialAd() {
          AerServConfig config = new AerServConfig(this, PLACEMENT_ID)
          config
            /**
              * This will enable the back button when a interstitial is shown. This will do nothing
              * when passed into a banner. This will also only work for ads coming form AerMarket,
              * S2S and tags. By default, the back button is only enabled when skippability is
              * enabled.
              */
            .enableBackButton(true)
            /**
              * As previously stated, the back button is only enabled when skippability is enabled.
              * This is set through the AerServ + InMobi dashboard. You can also override the time for when
              * the back button is enabled.
              */
            .setBackButtonTimeout(5000);
          interstitial = new AerServInterstitial(config);
          interstitial.show();
        }
      } 
      
    • Header Bidding Requests

      The Header Bidding flag is now enabled by default, and "useHeaderBidding" has been deprecated and is no longer needed.

Version History

  • 9.0.4: 3/3/20
  • Added support for InMobi Initialization callback
  • Improvements and Bug Fixes
  • Interface Changes

    - APIs Added

    • InMobiSdk
      public static void init(@NonNull final Context context, @NonNull @Size(min = 32, max = 36) String accountId, @Nullable JSONObject consentObject, @Nullable final SdkInitializationListener sdkInitializationListener)
    • SdkInitializationListener
      void onInitializationComplete(@Nullable Error error)

    - APIs Deprecated

    • InMobiSdk
      public static @InitializationStatus String init(@NonNull final Context context, @NonNull @Size(min = 32, max = 36) String accountId)

      public static @InitializationStatus String init(@NonNull final Context context, @NonNull @Size(min = 32, max = 36) String accountId, @Nullable JSONObject consentObject)
  • 9.0.2: 01/27/20
  • Added support for success/failure status for InMobi Initialization
  • Proactive detection of abnormal network calls by fraudulent creatives
  • Improvements and Bug Fixes
  • Interface Changes

    - APIs Updated

    • InMobiSdk
      public static @InitializationStatus String init(@NonNull final Context context, @NonNull @Size(min = 32, max = 36) String accountId)

      public static @InitializationStatus String init(@NonNull final Context context, @NonNull @Size(min = 32, max = 36) String accountId, @Nullable JSONObject consentObject)
  • 9.0.1: 10/25/19
  • Added support for IAB GDPR consent string
  • Updated OMSDK to v1.2.19
  • Added Banner refresh support from SSUI
  • Added support for Facebook Audience Network 5.5
  • Bug Fixes for SDK and AudienceBidder Plugin
  • 9.0.0: 9/20/19
  • Modular SDK
    - Added an ability to integrate Mediation as a separate module.
  • Added support for Android 10
  • Support for Mopub 5.8
  • Interface Changes
    • - APIs added
      AerServTransactionInformation

      public String getCreativeID()
    • - APIs removed
      • InMobiNative
        public InMobiNative(Context context, long placementId, NativeAdListener listener)

        public void setNativeAdListener(NativeAdListener listener)
      • InMobiNative.NativeAdListener
      • InMobiBanner
        public void setListener(BannerAdListener listener)
      • InMobiBanner.BannerAdListener
      • InMobiInterstitial
        public InMobiInterstitial(Context context, long placementId, InterstitialAdListener2 listener)

        public void setInterstitialAdListener(InterstitialAdListener2 listener)
      • InMobiInterstitial.InterstitialAdListener2
  • Bug fixes and performance improvements
  • 8.2.1: 8/22/19
    • Bug Fixes for SDK and AudienceBidder Plugin
  • 8.2.0: 8/5/19
    • Chrome Custom tabs support
    • Thread Optimizations
    • Bug Fixes for SDK and AudienceBidder Plugin
  • 8.1.3: 7/18/19
    • Support for Audience Bidding for DFP
    • Bug Fixes
  • 8.1.2: 6/19/19
    • Updated AdColony SDK support to 3.3.10
    • Updated Audience Network (Facebook) support to 5.3.1
  • 8.1.1: 5/27/19
    • Support for new Picasso version 2.71828
    • Bug Fixes
  • 8.1.0: 5/14/19
    • DFP Plugin Support
    • Mopub Audience Bidding Plugin Keyword Handling
  • 8.0.9: 4/22/19
    • Bug Fixes
  • 8.0.8: 4/17/19
    • Bug Fixes
  • 8.0.7: 4/5/19
    • Bug Fixes
    • Updated AudienceBidder to v1.0.1
      • Support for granular keywords
      • Fixed issue with updateBid not working with MoPub's refresh
      • Replaced source file with a aar
      • Various API Changes (see documentation)
  • 8.0.5: 3/11/19
    • Audience Bidder for the Mopub Plugin
    • Telaria Adapter Deprecation
    • Flurry Banner Adapter Deprecation
    • Applovin 3rd Party API Reporting updates
    • Chartboost 3rd Party API Reporting updates
    • Mediated SDK updates
    • Bug Fixes
  • 8.0.1: 11/28/18
    • Unified InMobi + AerServ SDK

このページは役に立ちましたか?

このページ

最終更新日: 31 Aug, 2021