Getting Started with Android

Add the CMP Library in Build Gradle

To use cmplibrary in your app, include com.sourcepoint.cmplibrary:cmplibrary:x.y.zas a dependency to your project's build.gradle. For example:

...
dependencies {
implementation 'com.sourcepoint.cmplibrary:cmplibrary:2.0.1'
}
  1. Open your existing Android project in Android Studio and select the File > New > New Module menu item.

  2. Scroll down and select Import .JAR/.AAR Package and click next.

  3. Browse and select the distributed cmplibrary-release.aar binary file (or the one you generated using the instructions in the last section)

  4. In your project's app/build.gradle file make sure you have cmplibrary-release as a dependency and also add com.google.guava:guava:20.0 as a dependency:

dependencies {
...
implementation project(":cmplibrary-release")
implementation("com.google.guava:guava:20.0")
}

5. Make sure in your project's settings.gradle file you have:

include ':app', ':cmplibrary-release'

6. Open app/src/main/AndroidManifest.xml and add android.permission.INTERNET permission if you do not have the permission in your manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.your-app">
<uses-permission android:name="android.permission.INTERNET" /> <application>
...
</application>
</manifest>

For SDK initialization, the three variables that should get set are accountId (in this example account 22 is the main Sourcepoint demo account), the siteName (this corresponds to the site name entered into the Sourcepoint UI for the app) and the stagingCampaign variable (this should always be set to false unless instructed by your Sourcepoint account team for troubleshooting purposes).

In your main activity, create an instance of ConsentLib class using ConsentLib.newBuilder() class function passing the configurations and callback handlers to the builder and call .run() on the instantiated ConsentLib object to load the CMP like following:

public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private ConsentLib consentLib;
private ConsentLib buildAndRunConsentLib(Boolean showPM) throws ConsentLibException {
return ConsentLib.newBuilder(22, "mobile.demo", this)
.setViewGroup(findViewById(android.R.id.content))
// optional, set custom targeting parameters value can be String and Integer
.setTargetingParam("MyPrivacyManager", showPM.toString())
//optional, set message time out , default is 5 seconds
.setMessageTimeOut(15000)
.setOnMessageReady(new ConsentLib.Callback() {
@Override
public void run(ConsentLib consentLib) {
if(consentLib.willShowMessage)
Log.i(TAG, "The message is about to be shown.");
else
Log.i(TAG, "The message doesn't need to be shown");
}
})
.setOnInteractionComplete(new ConsentLib.Callback() {
@Override
public void run(ConsentLib c) {
try {
c.getCustomVendorConsents(new String[]{}, new ConsentLib.OnLoadComplete() {
@Override
public void onSuccess(Object result) {
HashSet<CustomVendorConsent> consents = (HashSet) result;
String myImportantVendorId = "5bf7f5c5461e09743fe190b3";
for (CustomVendorConsent consent : consents)
if (consent.id.equals(myImportantVendorId))
Log.i(TAG, "Consented to My Important Vendor: " + consent.name);
}
}); c.getCustomPurposeConsents(new ConsentLib.OnLoadComplete() {
public void onSuccess(Object result) {
HashSet<CustomPurposeConsent> consents = (HashSet) result;
for (CustomPurposeConsent consent : consents)
Log.i(TAG, "Consented to purpose: " + consent.name);
}
}); // Example usage of getting IAB vendor consent results for a list of vendors
boolean[] IABVendorConsents = c.getIABVendorConsents(new int[]{81, 82});
Log.i(TAG, String.format("Consented to IAB vendors: 81 -> %b, 82 -> %b",
IABVendorConsents[0],
IABVendorConsents[1]
)); // Example usage of getting IAB purpose consent results for a list of purposes
boolean[] IABPurposeConsents = c.getIABPurposeConsents(new int[]{2, 3});
Log.i(TAG, String.format("Consented to IAB purposes: 2 -> %b, 3 -> %b",
IABPurposeConsents[0],
IABPurposeConsents[1]
)); } catch (ConsentLibException e) {
e.printStackTrace();
}
}
})
.setOnErrorOccurred(new ConsentLib.Callback() {
@Override
public void run(ConsentLib c) {
Log.d(TAG, "Something went wrong: ", c.error);
}
})
// generate ConsentLib at this point modifying builder will not do anything
.build();
} @Override
protected void onResume() {
super.onResume();
try {
consentLib = buildAndRunConsentLib(false);
consentLib.run();
} catch (ConsentLibException e) {
e.printStackTrace();
}
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.review_consents).setOnClickListener(new View.OnClickListener() {
public void onClick(View _v) {
try {
consentLib = buildAndRunConsentLib(true);
consentLib.run();
} catch (ConsentLibException e) {
e.printStackTrace();
}
}
});
} @Override
protected void onDestroy() {
super.onDestroy();
if(consentLib != null ) { consentLib.destroy(); }
}
}

The functions to access the consent data are executed inside of the onInteractionComplete event.

The functions in this section of the document explain how to retrieve consent information for both IAB and Non-IAB vendors and purposes. SharedPreferences is used to store small data of the application

Retrieve Standard IAB Consent String

The following method is used to retrieve the standard IAB Consent string from UserDefaults.

/* @param customVendorIds an array of vendor ids - currently needs to be retrieved from the SourcePoint UI * @param callback - callback that will be called with an array of boolean indicating if the user has given consent or not to those vendors. */public void getCustomVendorConsents(final String[] customVendorIds, final OnLoadComplete callback) { }
  1. This function should be called either during the onInteractionComplete callback or after it has returned.

  2. Returns a IAB consent string that can be passed as a daisybit parameter in an OpenRTB bid request.

Retrieve Purpose Consents

The following method is used to retrieve the purpose consents from SharedPreferences.

// Example usage of getting IAB purpose consent results for a list of purposes /* * This method receives a callback which is called with an Array of all the purposes ({@link Consent}) the user has given consent for. * @param callback called with an array of {@link Consent} */public void getCustomPurposeConsents(final OnLoadComplete callback) {}

Get IAB consent

The following method is used to retrieve the IAB consents given to each vendor ID in the array passed as a parameter.

/* @param vendorIds an array of standard IAB vendor IDs. * @return an array with same size as vendorIds param representing the results in the same order. * @throws ConsentLibException if the consent is not dialog completed or the *consent string is not present in SharedPreferences. */public boolean[] getIABVendorConsents(int[] vendorIds) throws ConsentLibException{}
  1. This function should be called either during the Callback, onInteractionComplete, or after it has returned.

  2. The function should passed an Array of vendor IDs.

  3. The function returns an Array of Boolean values indicating whether the user has given consent to the corresponding vendor.

Check IAB purpose

The following method is used to check whether consent was provided for the IAB purposes passed as parameter.

/* @param purposeIds an array of standard IAB purpose IDs. * @return an array with same size as purposeIds param representing the results in the same order. * @throws ConsentLibException if the consent dialog is not completed or the * consent string is not present in SharedPreferences. */public boolean[] getIABPurposeConsents(int[] purposeIds) throws ConsentLibException {}
  1. This function should be called either during the Callback, onInteractionComplete, or after it has returned.

  2. This function is passed an Array of purpose IDs.

  3. This function returns an Array of Boolean values indicating if the user has given consent to the corresponding purpose.

Check Non-IAB consent

The following method is used to check whether consent was provided to the non-IAB consents passed as parameter.

/* @param customVendorIds an array of vendor ids - currently needs to be provided by Sourcepoint * @param callback - callback that will be called with an array of boolean indicating if the user has given consent or not to those vendors. */public void getCustomVendorConsents(final String[] customVendorIds, final OnLoadComplete callback) {}
  1. This function should be called either during the Callback, onInteractionComplete, or after it has returned.

  2. This function is passed an Array of vendor IDs.

  3. This function returns an Array of Boolean values indicating if the user has given consent to the corresponding vendor IDs.

Check Non-IAB purposes

The following method is used to check whether consent was provided to the non-IAB purposes passed as parameter.

/*
* This method receives a callback which is called with an Array of all the purposes ({@link Consent}) the user has given consent for. * @param callback called with an array of {@link Consent} */public void getCustomPurposeConsents(final OnLoadComplete callback) {}
  1. This function should be called either during the Callback, onInteractionComplete, or after it has returned.

  2. This function is passed an Array of purpose IDs.

  3. This function returns an Array of Boolean values indicating if the user has given consent to the corresponding purpose IDs.

To display the proper message and privacy manager within the app, the app needs to be linked to your account in the Sourcepoint UI and a "site" within the UI. This is done with when the ConsentViewController.init(accountId: 22, siteName: "mobile.demo", stagingCampaign: false) line of code. In this example the accountId of 22 corresponds to the "Account ID" found in the account page in the Sourcepoint UI (see screenshot below).

The siteName parameter is a name defined in the site section of the Dialogue portion of the Sourcepoint UI. The name is arbitrary and just needs to be a name that makes sense to you. Site names such as ios.app and or android.app are both valid names.

Some of the functions above require using IDs retrieved from the Sourcepoint UI. In particular, the functions for retrieving consent data on Non-IAB vendors and purposes.

To get a particular vendor or purpose ID please do the following:

  1. Go to the Vendor List window of the Consent section of the Sourcepoint UI.

  2. Click on the vendor or purpose for which you are getting the ID.

  3. Retrieve the ID from window (see screenshot below).

This is the ID that is used in functions designed to get the consent status of a particular vendor or purpose for a user.

If you have any additional questions, please contact your Sourcepoint account manager.