API Reference
Overview
In this article you'll find all the CMP SDK public methods for Android.
Active Methods
Get Domain Info
This method returns a JSONObject containing all the information about the domain including rulesets and template configurations.
new OTPublishersHeadlessSDK(MainActivity.this).getDomainInfo()
Get Common Data
This method returns a JSONObject which contains the branding information which includes keys for determining colors and styles in the UI specific to a template configured for the user's geolocation.
new OTPublishersHeadlessSDK(MainActivity.this).getCommonData()
Get Groups Data
This method returns a JSONObject containing the information about all the categories and sdk ids specific to a template configured for the user's geolocation.
new OTPublishersHeadlessSDK(MainActivity.this).getDomainGroupData()
Get Banner Data
This method returns a JSONObject which contains all the keys required to render a banner.
new OTPublishersHeadlessSDK(MainActivity.this).getBannerData()
Banner Allow All
Call this method when user selects Allow All button on the Banner. This will opt-in the user to all Category/Purposes.
new OTPublishersHeadlessSDK(context).saveConsent(OTConsentInteractionType.BANNER_ALLOW_ALL)
IAB TCF2
For IAB TCF2 templates, this method also sets the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-in. These values will be encoded into the TC String and saved to UserDefaults.
Banner Reject All
Call this method when user selects Reject All button on the Banner. This will opt-out the user to all Category/Purposes.
new OTPublishersHeadlessSDK(context).saveConsent(OTConsentInteractionType.BANNER_REJECT_ALL)
IAB TCF2
For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-out. These values will be encoded into the TC String and saved to UserDefaults.
Banner Close
Call this method when closing the Banner. It will save the default consent values for each Category/Purpose based on the geolocation rule.
new OTPublishersHeadlessSDK(context).saveConsent(OTConsentInteractionType.BANNER_CLOSE)
IAB TCF2
For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any). These values will be encoded into the TC String and saved to UserDefaults.
Get Preference Center Data
This method returns a JSONObject which contains all the keys required to render a Preference Center.
new OTPublishersHeadlessSDK(MainActivity.this).getPreferenceCenterData()
Preference Center Allow All
Call this method when user selects Allow All button on the Banner. This will opt-in the user to all Category/Purposes.
new OTPublishersHeadlessSDK(context).saveConsent(OTConsentInteractionType.PC_ALLOW_ALL)
IAB TCF2
For IAB TCF2 templates, this method also sets the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-in. These values will be encoded into the TC String and saved to UserDefaults.
Preference Center Reject All
Call this method when user selects Reject All button on the Banner. This will opt-out the user to all Category/Purposes.
new OTPublishersHeadlessSDK(context).saveConsent(OTConsentInteractionType.PC_REJECT_ALL)
IAB TCF2
For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-out. These values will be encoded into the TC String and saved to UserDefaults.
Programmatically Update and Save Purpose Consent
These methods are typically utilized in a BYOUI approach and can be used to update and save consent programmatically for a specific category to true
or false
based on user input. Simply pass in the group/category ID and consent status to update the values.
Usage
Modifying the user's consent is a two step approach. updatePurposeConsent()
is used to set the state of the consent (toggles) on the UI and saveConsent()
is used to commit and save the consent to local storage. saveConsent
MUST be called or consent will NOT be committed and changed.
OTPublishersHeadlessSDK otPublishersHeadlessSDK = new OTPublishersHeadlessSDK(context);
otPublishersHeadlessSDK.updatePurposeConsent("C0004", true);
otPublishersHeadlessSDK.updatePurposeConsent("C0003", false, true);
otPublishersHeadlessSDK.saveConsent(OTConsentInteractionType.PC_CONFIRM);
Parameters
forGroup
- Category/Group ID of the category to be modified (e.g. C0001, C0002, C0004, etc.)consentValue
- Consent status given by the user for a category/group. Boolean type.updateHierarchy
- This field is optional. Set to true if you have child categories that need to be updated with the parentOTConsentInteractionType
- Denotes the type of interaction used to commit/save consent (e.g. banner allow all, preference center confirm, preference center reject, etc.)
Sample implementation on how to update and save, if you have multiple categories to update at a time.
OTPublishersHeadlessSDK otPublishersHeadlessSDK = new OTPublishersHeadlessSDK(context);
otPublishersHeadlessSDK.updatePurposeConsent("C0004", true);
otPublishersHeadlessSDK.updatePurposeConsent("C0005", true);
otPublishersHeadlessSDK.updatePurposeConsent("C0006", true);
otPublishersHeadlessSDK.updatePurposeConsent("IABV2_6", true);
otPublishersHeadlessSDK.saveConsent(OTConsentInteractionType.PC_CONFIRM)
(Optional) Update Toggle State in UI
If you're looking to update in real time the toggle state in the out of the box preference center UI, the configurations below must be added:
public OTConfiguration getOTConfiguration(@NonNull Context context) {
OTConfiguration.OTConfigurationBuilder otConfigurationBuilder = OTConfiguration.OTConfigurationBuilder.newInstance();
otConfigurationBuilder.syncOTUIWithBYOUIMethods(true);
return otConfigurationBuilder.build();
}
OTConfiguration config = getOTConfiguration(getApplicationContext());
new OTPublishersHeadlessSDK(this).showPreferenceCenterUI(RenderNativeUIActivity.this, config);
Get Vendor List UI
This method will allow your application to retrieve the JSONObject required to render the vendor list UI. It returns a JSONObject containing local state of active IAB Vendor List if values are updated without save using updateVendorConsent/updateVendorLegitInterest. Returns previously saved IAB vendor state if nothing has changed, null if no active vendors are found.
new OTPublishersHeadlessSDK(this).getVendorListUI()
Get Vendor List Data
This method will allow your application to retrieve the JSONObject required to render the vendor list UI. It returns a JSONObject containing saved state of active IAB Vendor List. Returns null if no active vendors are found.
new OTPublishersHeadlessSDK(this).getVendorListData()
Get Details of a Particular Vendor
This method allows your application to retrieve a JSONObject containing all the details about a vendor by passing the vendor id. Returns null if the id passed is invalid or the vendor is not configured for you in the OneTrust console.
The vendor details contain vendor name, id, consent / legitimate interests values, and details about other properties configured in the OneTrust console.
The OTVendorListMode is one of GENERAL
, IAB
, or GOOGLE
depending on the type of vendor list being referenced. The second argument is the ID of the vendor as a string.
JSONObject general = new OTPublishersHeadlessSDK(this).getVendorDetails(OTVendorListMode.GENERAL,"V1");
JSONObject iab = new OTPublishersHeadlessSDK(this).getVendorDetails(OTVendorListMode.IAB,"700");
JSONObject google = new OTPublishersHeadlessSDK(this).getVendorDetails(OTVendorListMode.GOOGLE,"34");
Parameters
- vendorType (OTVendorListMode)
- vendorId (string)
Get Total Vendor Count
This method allows you to return the total number of IAB TCF vendors your app is using. This can be useful in instances where you're building your own banner and need to include the vendor count as required by IAB.
JSONObject vendorCount = new OTPublishersHeadlessSDK(context).getVendorListData(OTVendorListMode.IAB);
vendorCount.length();
Query Consent Status for a Category
Query the current consent status for any of the Categories included in your application. This can be used to determine what privacy action is needed at app launch or anytime the consent status is needed without being notified by an event broadcast. Simply pass in the Category ID (eg. C0001) and the method will return the current consent status.
new OTPublishersHeadlessSDK(this).getConsentStatusForGroupId("C0004");
Parameters
- CustomGroupId: Custom group id contained in the group json object returned by SDK public methods. Custom group ids for each category can be obtained from OneTrust console as well.
Return Values
- 1 = Consent is given (An end user interacts with the SDK and gives consent.)
- 0 = Consent is not given (An end user interacts and does not give consent.)
- -1 = Consent has not been collected (The SDK is not yet initialized for the end user.)
Query Consent Status for a Specific SDK
Query the current consent status for any of the SDKs included in your application. This can be used to determine what privacy action is needed at app launch or anytime the consent status is needed without being notified by an event broadcast. Simply pass in the SDK ID and the method will return the current consent status.
new OTPublishersHeadlessSDK(this).getConsentStatusForSDKId("2368810c-94da-4f18-ab92-c55c5f74cca9");
Parameters
- SDK GUID - SDK id contained in the group json object returned by SDK public methods. SDK ids for each SDK configured in the application can be obtained from OneTrust console as well.
Return Values
- 1 = Consent is given (An end user interacts with the SDK and gives consent.)
- 0 = Consent is not given (An end user interacts and does not give consent.)
- -1 = Consent has not been collected (The SDK is not yet initialized for the end user.)
Reset updated consent values for all Categories
This method will allow your application to reset the updated values for all the categories. This method can be called when user skips the consent view by closing the Preference Center or on any other scenarios in which application has to clear the user selections given by the user.
On calling this method SDK will reset the values of all categories / SDKs to previously saved values. If no consent has been saved prior to calling this method, then values will be reset according to the default consent model configured for each category.
new OTPublishersHeadlessSDK(context).resetUpdatedConsent();
Should Show Banner
This method will inform your application if the OneTrust Banner has to be presented to the user or not for the user's current location. This method will return true or false based on the geolocation configurations you have assigned for the application in OneTrust environment.
This can be used by your app to determine if functions to build and display UI have to be called.
new OTPublishersHeadlessSDK(this).shouldShowBanner();
Return Values
- true = show banner for that geolocation
- false = don't show banner for user's geolocation / consent has been taken already.
Clear SDK Data
This method will delete all the data saved in the SDK. When the application calls this method, SDK will:
- Clear all values saved in SharedPreferences
- Clear all previously given user consent values, if any
- Reset all public method values to defaults
new OTPublishersHeadlessSDK(context).clearOTSDKData();
Multi Profile Consent
This feature allows you to store multiple consents on the device if you allow multiple user profiles to use one login. View more information here: https://developer.onetrust.com/onetrust/docs/multi-profile-consent#android
Deprecated Methods
acceptAll()
acceptAll()
Method | Swift: OTPublishersHeadlessSDK(context).acceptAll() |
---|---|
Description | Method connected with the Accept All button for both Banner and Preference Center. |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.11.0 |
Migrate To | Applications should migrate to using either: saveConsent(OTConsentInteractionType.BANNER_ALLOW_ALL) saveConsent(OTConsentInteractionType.PC_ALLOW_ALL) |
rejectAll()
rejectAll()
Method | Swift: OTPublishersHeadlessSDK(context).rejectAll() |
---|---|
Description | Method connected with the Reject All button for both Banner and Preference Center. |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.11.0 |
Migrate To | Applications should migrate to using either: saveConsent(OTConsentInteractionType.BANNER_REJECT_ALL) saveConsent(OTConsentInteractionType.PC_REJECT_ALL) |
saveDefaultConsentValues()
saveDefaultConsentValues()
Method | Swift: OTPublishersHeadlessSDK(context).saveDefaultConsentValues() |
---|---|
Description | Method used when a user Closes the Banner and the default consent for the geolocation is saved to disk. |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.11.0 |
Migrate To | Applications should migrate to using saveConsent(OTConsentInteractionType.BANNER_CLOSE) |
saveConsentValue()
saveConsentValue()
Method | Swift: OTPublishersHeadlessSDK(context).saveConsentValue() |
---|---|
Description | Method for saving Category/Purpose consent status changes to disk once they've been updated with updatePurposeConsent(forGroup: , consentValue: ) . |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.11.0 |
Migrate To | Applications should migrate to saveConsent(OTConsentInteractionType.PC_CONFIRM) |
initOTSDKData
initOTSDKData
Method | Java: OTPublishersHeadlessSDK(MainActivity.this).initOTSDKData() |
---|---|
Description | The way the SDK initializes. |
Reason | We are moving away from storing the entire JSON response as a part of this method, and instead will be returning a new OTResponse object in case the application needs to save the entire JSON response. |
Deprecated Version | 6.15.0 |
Migrate To | Applications should migrate to using startSDK() |
getOTSDKData
getOTSDKData
Method | Java: new OTPublishersHeadlessSDK(MainActivity.this).getOTSDKData() |
---|---|
Description | Allows application to access full JSON data payload. |
Reason | We are moving away from storing the entire JSON response in string format in User Defaults. Instead, we will be storing cultureData , domainData , and profile separately. |
Deprecated Version | 6.15.0 |
Migrate To | Applications should migrate to using either: getDomainGroupData() getDomainInfo() getCommonData() |
Override Data subject Identifier
OneTrust SDK logs consent transactions based on consent logging feature that have been enabled in OneTrust's environment. By default, consent logging feature will generate a unique identifier for each device and log transactions considering it as an anonymous user.
OneTrust provides a method to override this randomly generated identifier by passing a valid String value for identifier variable. This method will set the value to SDK and show as the Data Subject Identifier in OneTrust environment while reviewing transactions. This method MUST be called after initializing the SDK.
If the identifier is set after user giving consent, then the last anonymous transaction and the subsequent transactions will be logged with the new identifier set by your application.
new OTPublishersHeadlessSDK(context).overrideDataSubjectIdentifier("user identifier");
Parameters
- identifier value - a valid String value
Set Data Subject Identifier
This method sets the identifier
for the User Profile the consent is being saved to.
- When the
identifier
is not set, the SDK will generate a unique (anonymous) identifier by default. - If an empty
identifier
is passed, OneTrust will remove the last saved identifier.
Requires SDK Init? | Yes |
---|---|
Method | setDataSubjectIdentifier("User Id") |
Arguments | id: string |
Returns | string |
new OTPublishersHeadlessSDK(context).setDataSubjectIdentifier("user identifier");
Get Data Subject Identifier
This method returns the Data Subject ID saved by the SDK. You can use this value to lookup Consent Receipts for a User on the OneTrust Admin.
Requires SDK Init? | Yes |
---|---|
Method | getDataSubjectIdentifier(); |
Arguments | n/a |
Returns | string |
new OTPublishersHeadlessSDK.getOTCache().getDataSubjectIdentifier();
Updated 5 months ago