Android App Implementation (SDK)

Introduction

Overview

InMobi CMP empowers site owners to efficiently handle consent across diverse devices and environments, including Android. The InMobi CMP strictly adheres to the IAB TCF v2.2 standard.

System Requirements

Ensure a minimum Android version 5.0 (API 21) or higher for seamless operation. While not mandatory, we highly recommend using Android Studio 4+ for an optimal experience.

User Interface (UI)

The CMP utilizes native UI components within a DialogFragment, providing an intuitive interface overlaying the current Activity.

Data Management

The IAB TCF v2 mobile specifications securely store all consent data, utilizing SharedPreferences for robust data management.

UI customisation

We have UI customization capabilities with our SDK. This feature empowers developers to tailor color schemes and font styles for all UI components used in the InMobi CMP This ensures seamless integration with the host application's UI style. For more information on customizing styles, see UI Customization for Mobile Android.

Known Issue

There is an issue with the accurate display of consent rates on the Privacy Properties page. However, the complete analytical reports remain accessible through the Reports button.

CMP SDK Configuration and Download

Before integrating InMobi CMP into your mobile app, make sure you have followed the instructions on how to protect an app. Once done, click Download SDK.

Find Your P-CODE

To initialize the SDK, you must provide your account's p-code for proper identification. After you log in to the InMobi CMP portal, you can see the p-code at the top right corner of the screen. However, as shown below, you must omit the initial two characters ("p-") when copying the code for use elsewhere.

Set up Android Studio Project

From Downloaded aar

  1. Place the .aar file into projects/libs directory of your application.
  2. In your application's build.gradle file, include the following Gradle dependencies:
    implementation files('libs/inmobicmp-1.0.0.aar')
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
    implementation "androidx.appcompat:appcompat:1.4.1" 
    implementation "androidx.constraintlayout:constraintlayout:2.1.3" 
    implementation "androidx.recyclerview:recyclerview:1.2.1" 
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'com.google.code.gson:gson:2.8.8'
    implementation "com.iabgpp:iabgpp-encoder:3.1.1"
    
    
  3. Ensure that the dependency versions are intercompatible.
  4. Add ProGuard Rules: In your app's proguard-rules.pro file, add the rules below:
    ## InMobi CMP
    -keep class com.inmobi.cmp.ChoiceCmp {public protected *;}
    -keep interface com.inmobi.cmp.ChoiceCmpCallback {public protected *;}
    -keep class com.inmobi.cmp.model.ChoiceError {public protected *;}
    -keep class com.inmobi.cmp.model.NonIABData {public protected *;}
    -keep class com.inmobi.cmp.model.PingReturn {public protected *;}
    -keep class com.inmobi.cmp.core.model.ACData {public protected *;}
    -keep class com.inmobi.cmp.core.model.TCData {public protected *;}
    -keep class com.inmobi.cmp.core.model.gbc.GoogleBasicConsents {public protected *;}
    -keep class com.inmobi.cmp.data.model.ChoiceStylesResources {public protected *;}
    -keep class com.inmobi.cmp.core.model.Vector {public protected *;}
    
    ##Gson
    -keepattributes Signature
    
    -keepattributes Annotation
    
    -dontwarn sun.misc.**
    
    -keep class com.google.gson.examples.android.model.** { <fields>; }
    
    -keep class * extends com.google.gson.TypeAdapter
    -keep class * implements com.google.gson.TypeAdapterFactory
    -keep class * implements com.google.gson.JsonSerializer
    -keep class * implements com.google.gson.JsonDeserializer
    
    -keepclassmembers,allowobfuscation class * {
      @com.google.gson.annotations.SerializedName <fields>;
    }
    
    -keep class com.google.gson.reflect.TypeToken
    -keep class * extends com.google.gson.reflect.TypeToken
    -keep public class * implements java.lang.reflect.Type
    
    ## AndroidX
    -dontwarn com.google.android.material.**
    -keep class com.google.android.material.** { *; }
    
    -dontwarn androidx.**
    -keep class androidx.** { *; }
    -keep interface androidx.* { *; }
    

Integrate InMobi CMP for Mobile Apps

SDK Integration

  1. To utilize the ChoiceCmpCallback functionality, implement the ChoiceCmpCallback interface.

    Kotlin

    import com.inmobi.cmp.ChoiceCmpCallback
    
    class ChoiceSampleApp: Application(), ChoiceCmpCallback
    

    Java

    import com.inmobi.cmp.ChoiceCmpCallback;
    
    class ChoiceSampleApp extends Application implements ChoiceCmpCallback
    
  2. To utilize ChoiceCmpCallback, implement the required methods. For detailed best practices on callbacks, see the next section.

    Kotlin

    import com.inmobi.cmp.ChoiceCmp
    import com.inmobi.cmp.ChoiceCmpCallback
    import com.inmobi.cmp.core.model.ACData
    import com.inmobi.cmp.core.model.GDPRData
    import com.inmobi.cmp.core.model.gbc.GoogleBasicConsents
    import com.inmobi.cmp.core.model.mspa.USRegulationData
    import com.inmobi.cmp.model.ChoiceError
    import com.inmobi.cmp.model.NonIABData
    import com.inmobi.cmp.model.PingReturn
    
    override fun onCCPAConsentGiven(consentString: String) {
        /* code */
    }
    
    override fun onCmpError(error: ChoiceError) {
        /* code */
    }
    
    override fun onCmpLoaded(info: PingReturn) {
        /* code */
    }
    
    override fun onCmpUIShown(info: PingReturn) {
        /* code */
    }
    
    override fun onGoogleBasicConsentChange(consents: GoogleBasicConsents) {
        /* code */
    }
    
    override fun onGoogleVendorConsentGiven(acData: ACData) {
        /* code */
    }
    
    override fun onIABVendorConsentGiven(gdprData: GDPRData) {
        /* code */
    }
    
    override fun onNonIABVendorConsentGiven(nonIABData: NonIABData) {
        /* code */
    }
    
    override fun onReceiveUSRegulationsConsent(usRegulationData: USRegulationData) {
        /* code */
    }
    
    override fun onUserMovedToOtherState() {
        /* code */
    }
    

    Java

    import com.inmobi.cmp.ChoiceCmp;
    import com.inmobi.cmp.ChoiceCmpCallback;
    import com.inmobi.cmp.core.model.ACData;
    import com.inmobi.cmp.core.model.GDPRData;
    import com.inmobi.cmp.core.model.gbc.GoogleBasicConsents;
    import com.inmobi.cmp.core.model.mspa.USRegulationData;
    import com.inmobi.cmp.model.ChoiceError;
    import com.inmobi.cmp.model.NonIABData;
    import com.inmobi.cmp.model.PingReturn;
    
    @Override
    public void onCCPAConsentGiven(String consentString) {
        // code
    }
    
    @Override
    public void onCmpError(ChoiceError error) {
        // code
    }
    
    @Override
    public void onCmpLoaded(PingReturn info) {
        // code
    }
    
    @Override
    public void onCmpUIShown(PingReturn info) {
        // code
    }
    
    @Override
    public void onGoogleBasicConsentChange(GoogleBasicConsents consents) {
        // code
    }
    
    @Override
    public void onGoogleVendorConsentGiven(ACData acData) {
        // code
    }
    
    @Override
    public void onIABVendorConsentGiven(GDPRData gdprData) {
        // code
    }
    
    @Override
    public void onNonIABVendorConsentGiven(NonIABData nonIABData) {
        // code
    }
    
    @Override
    public void onReceiveUSRegulationsConsent(USRegulationData usRegulationData) {
        // code
    }
    
    @Override
    public void onUserMovedToOtherState() {
        // code
    }
    
  3. In your Application class's onCreate method, add the following code snippet. The startChoice method requires the application context, your app's package ID (matching the web portal), your p-code, a delegate object, and an optional parameter for customization styles.

    Kotlin

    import com.inmobi.cmp.ChoiceCmp
    import com.inmobi.cmp.ChoiceCmpCallback
    
    class ChoiceSampleApp : Application(), ChoiceCmpCallback { 
        override fun onCreate() { 
            super.onCreate() 
            ChoiceCmp.startChoice( 
                app = this, 
                packageId = "packageId", 
                pCode = "pCode", 
                callback = this 
            ) 
        } 
    }
    

    Java

    import com.inmobi.cmp.ChoiceCmp;
    import com.inmobi.cmp.ChoiceCmpCallback;
    
    class ChoiceSampleApp extends Application implements ChoiceCmpCallback {  
    
        @Override 
        public void onCreate() { 
            super.onCreate(); 
            ChoiceCmp.startChoice( 
                    this, 
                    "packageId", 
                    "pcode", 
                    this, 
                    new ChoiceStylesResources() 
            ); 
        } 
    }
    

    For Kotlin users, the last parameter is optional. For more details, see UI Customization for Mobile Android.

  4. To enable users to adjust their consent preferences anytime, implement a feature that allows the CMP dialog to be manually triggered. This can be incorporated into a menu alongside your app's privacy policy or other settings. The startChoice method can display the popup when necessary. To open the CMP, make the following call:

    Kotlin

    import com.inmobi.cmp.ChoiceCmp
    
    ChoiceCmp.forceDisplayUI(activity)
    

    Java

    import com.inmobi.cmp.ChoiceCmp;
    
    ChoiceCmp.forceDisplayUI(activity);
    

    The SDK actively monitors lifecycle events to ensure that consent information is readily available. If consent data is not found, the CMP will trigger automatically, prompting the user for their preferences. Subsequently, each time a user interaction with the CMP occurs, the associated callbacks will be triggered.

Implement Callback

Implementing all three consent callbacks is imperative, even if you haven't configured all the consent features. This ensures comprehensive coverage and prevents any potential oversight in consent handling.

  1. Manage IAB Vendor Compliant Consent: The method onIABVendorConsentGiven method is triggered when the user consents to IAB-compliant vendors. For more information, see IAB-compliant vendors. Ideally, IAB-compliant mobile frameworks will autonomously adapt to this consent, configuring themselves accordingly. However, it's worth noting that limited IAB-compliant mobile frameworks are available. It is advisable to reach out to your vendor for further clarification. In cases where the framework is not compliant, the responsibility of handling consent falls on you. If the framework includes a setup method that is called in the onCreate, it should be relocated to this section and executed after consent is verified. For example:

    Kotlin

    override fun onIABVendorConsentGiven(tcData: TCData) { 
        //Use TCData to know the consent information related to IAB vendors 
    }
    

    Java

    @Override 
    public void onIABVendorConsentGiven(@NonNull TCData tcData) { 
        //Use TCData to know the consent information related to IAB vendors 
    }
    

    To access the TC String from the shared preference, retrieve it by accessing the IABTCF_TCString key from the < PackageName >_preferences  preference file upon receiving the consent.

  2. Manage Non-IAB Vendor Consent: onNonIABVendorConsentGiven callback is triggered for vendors already configured in the portal and does not automatically verify consent. In this case, consent is provided in a binary manner: either a complete yes or no for all services. To verify consent, retrieve the specific vendor by their ID using the following method:

    Kotlin

    override fun onNonIABVendorConsentGiven(nonIABData: NonIABData) { 
        //Use NonIABData to know the consent information related to Non-IAB vendors 
    }
    

    Java

    @Override 
    public void onNonIABVendorConsentGiven(@NonNull NonIABData nonIABData) { 
        //Use NonIABData to know the consent information related to Non-IAB vendors 
    }
    
  3. Manage Google Vendor Consent: The other main callback to be aware of is onGoogleVendorConsentGiven. This callback is called only if you have Google Vendors turned on in the portal. For more information about Google Vendors, please see Google’s Additional Consent technical specification. Similar to the other callbacks, you should use this callback to manage the Google Vendors.

    Kotlin

    override fun onGoogleVendorConsentGiven(acData: ACData) { 
        //Use ACData to know the consent information related to Google vendors  
    }
    

    Java

    @Override 
    public void onGoogleVendorConsentGiven(@NonNull ACData acData) { 
        //Use ACData to know the consent information related to Google vendors 
    }
    

    While not essential, additional callbacks are available for debugging or advanced scenarios. One such callback is onCmpError, which triggers whenever the CMP exits unexpectedly and fails to collect consent.

  4. Manage MSPA consent: The callback onReceiveUSRegulationsConsent is triggered when the user gives consent to MSPA. Since it is opt-out by default, the callback is also triggered when the consent changes. You will get consent details in usRegulationData.

    Kotlin

    override fun onReceiveUSRegulationsConsent(usRegulationData: USRegulationData) {
        // use usRegulationData to retrieve info related to MSPA
    }
    
    

    Java

    @Override
    public void onReceiveUSRegulationsConsent(USRegulationData usRegulationData) { 
        // use usRegulationData to retrieve info related to MSPA 
    }
    
    
  5. User Location Changed: The callback onUserMovedToOtherState is triggered when the user changes location due to which the applicable MSPA consent changes. You can re-trigger MSPA if you want new consent according to a new location.

    Kotlin

    override fun onUserMovedToOtherState() {
    	//use this to retrigger MSPA to renew consent
    }
    
    

    Java

    @Override
    public void onUserMovedToOtherState() { 
        // Use this to retrigger MSPA to renew consent 
    }
    
    

U.S Regulation (MSPA Integration)

Display MSPA Screen

After successfully initialising the SDK, present the MSPA screen by invoking the following method:

Kotlin

ChoiceCmp.showUSRegulationScreen(this)

Java

ChoiceCmp.showUSRegulationScreen(this);

Note

If you select opt-out screen notice trigger from the portal, the MSPA consent screen will be presented automatically and the corresponding consent will be taken.

Once the user has given consent, onReceiveUSRegulationsConsent will be fired.

CCPA Integration

Display CCPA Screen

After initializing the SDK, present the CCPA screen by invoking the following method from ChoiceCmp object and passing the Activity:

Kotlin

import com.inmobi.cmp.ChoiceCmp

ChoiceCmp.showCCPAScreen(activity)

Java

import com.inmobi.cmp.ChoiceCmp;

ChoiceCmp.showCCPAScreen(activity);

Access IABUSPrivacy_String

Once the user gives consent in the CCPA screen, you can retrieve the IABUSPrivacy_String upon receiving the consent from the <PackageName>_preferences preference file.

Note

CCPA is deprecated by IAB. Use MSPA instead.

On This Page

Last Updated on: 03 Jul, 2024