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'
    
    Ensure that the dependency versions are intercompatible.
  3. If you are working with Java, include the Kotlin standard library dependency.
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
    

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.core.model.TCData
    import com.inmobi.cmp.model.NonIABData
    import com.inmobi.cmp.model.ChoiceError
    import com.inmobi.cmp.core.model.ACData
    import com.inmobi.cmp.model.PingReturn
    
    override fun onCmpLoaded(pingReturn: PingReturn) { 
         /* code */ 
    }  
    override fun onCmpUIShown(pingReturn: PingReturn) { 
        /* code */ 
    }  
    override fun onIABVendorConsentGiven(tcData: TCData) { 
        /* code */ 
    }  
    override fun onNonIABVendorConsentGiven(nonIABData: NonIABData) { 
        /* code */ 
    }  
    override fun onCmpError(choiceError: ChoiceError) { 
        /* code */ 
    }  
    override fun onGoogleVendorConsentGiven(acData: ACData) { 
        /* code */ 
    }  
    override fun onCCPAConsentGiven(s: String) { 
        /* code */ 
    }
    

    Java

    import com.inmobi.cmp.core.model.TCData;
    import com.inmobi.cmp.model.NonIABData;
    import com.inmobi.cmp.model.ChoiceError;
    import com.inmobi.cmp.core.model.ACData;
    import com.inmobi.cmp.model.PingReturn;
    
    @Override 
    public void onCmpLoaded(@NonNull PingReturn pingReturn) { 
        /* code */ 
    }  
    @Override 
    public void onCmpUIShown(@NonNull PingReturn pingReturn) { 
        /* code */ 
    }  
    @Override 
    public void onIABVendorConsentGiven(@NonNull TCData tcData) { 
        /* code */ 
    }  
    @Override 
    public void onNonIABVendorConsentGiven(@NonNull NonIABData nonIABData) { 
        /* code */ 
    }  
    @Override 
    public void onCmpError(@NonNull ChoiceError choiceError) { 
        /* code */ 
    }  
    @Override 
    public void onGoogleVendorConsentGiven(@NonNull ACData acData) { 
        /* code */ 
    }  
    @Override 
    public void onCCPAConsentGiven(@NonNull String s) { 
        /* 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.

CCPA Integration

Display CCPA Screen

After initializing the SDK, you can 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.

On This Page

Last Updated on: 22 Apr, 2024