Integration
How to use AppConsent
1. Get your AppKey from AppConsent : https://app.appconsent.io
2. Create AppConsent Instance
- Clear template development kit (SDK)
- Classic template development kit (SDK)
- TV template development kit (SDK)
- Kotlin
- Java
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.sfbx.appconsentv3.AppConsent
import com.sfbx.appconsentv3.ui.listener.OnPresentNoticeListener
class MainActivity : AppCompatActivity() {
private var appConsent: AppConsent? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
Shows whether the SDK has already been initialized
*/
if (!com.sfbx.appconsentv3.ui.AppConsentSDK.isSdkInitialized()) {
initSfbxModule()
} else {
if (appConsent == null) {
/*
Retrieves the AppConsent instance or null if it has not yet been instantiated, for example
*/
appConsent = com.sfbx.appconsentv3.ui.AppConsentSDK.getInstance()
}
}
}
/*
Initializes the consent management platform module when the activity is created
*/
private fun initSfbxModule() {
com.sfbx.appconsentv3.ui.AppConsentSDK.initialize(
appKey = "{APP_KEY}"
) { appConsentInitialized ->
/*
Use the instance received by the onReady callback
This has been successfully initialized
*/
appConsent = appConsentInitialized
/*
Registers with CMP callback to know when the user
has given consent, or if an error has occurred
*/
appConsent?.setOnPresentNoticeListener(object : OnPresentNoticeListener {
override fun presentConsentError(error: Throwable?) {
/*
An error has occurred
*/
}
override fun presentConsentGiven() {
/*
The user has given his consent
*/
}
})
/*
Try to display the CMP according to certain rules.
*/
val isNoticeDisplayed = appConsentInitialized.tryToDisplayNotice(false)
if (!isNoticeDisplayed) {
/*
The user has already given consent;
The user is not part of an area subject to the application of GDPR;
etc.
*/
}
}
}
}
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.sfbx.appconsentv3.AppConsent;
import com.sfbx.appconsentv3.ui.listener.OnPresentNoticeListener;
import kotlin.Unit;
public class MainActivity extends AppCompatActivity {
private AppConsent appConsent = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
Shows whether the SDK has already been initialized
*/
if (!com.sfbx.appconsentv3.ui.AppConsentSDK.isSdkInitialized()) {
initSfbxModule();
} else {
if (appConsent == null) {
/*
Retrieves the AppConsent instance or null if it has not yet been instantiated, for example
*/
appConsent = com.sfbx.appconsentv3.ui.AppConsentSDK.getInstance();
}
}
}
/*
Initializes the consent management platform module when the activity is created
*/
private void initSfbxModule() {
com.sfbx.appconsentv3.ui.AppConsentSDK.initialize(
"{APP_KEY}",
appConsentInitialized -> {
/*
To avoid certain problems, use the instance received by the onReady callback
This has been successfully initialized
*/
appConsent = appConsentInitialized;
/*
Registers with CMP callback to know when the user
has given consent, or if an error has occurred
*/
appConsent.setOnPresentNoticeListener(new OnPresentNoticeListener() {
@Override
public void presentConsentError(@NonNull Throwable error) {
/*
An error has occurred
*/
}
@Override
public void presentConsentGiven() {
/*
The user has given his consent
*/
}
});
/*
Try to display the CMP according to certain rules.
*/
final boolean isNoticeDisplayed = appConsent.tryToDisplayNotice(true);
if (!isNoticeDisplayed) {
/*
The user has already given consent;
The user is not part of an area subject to the application of GDPR;
etc.
*/
}
return Unit.INSTANCE;
});
}
}
- Kotlin
- Java
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.sfbx.appconsent.AppConsent
import com.sfbx.appconsent.ui.AppConsentSDK
import com.sfbx.appconsent.ui.AppConsentTheme
import com.sfbx.appconsent.ui.listener.OnPresentNoticeListener
import com.sfbx.appconsent.ui.model.ACConfiguration
class MainActivity : AppCompatActivity() {
private var appConsent: AppConsent? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
If you use the CMP several times, avoid initializing it several times.
Use AppConsentSDK.getInstance to retrieve the already initialized instance, after checking whether it has already been initialized, or use the AppConsentSDK.initialize method.
*/
if (!AppConsentSDK.isSdkInitialized()) {
initSfbxModule()
} else {
appConsent = AppConsentSDK.getInstance()
}
}
/*
Initializes the consent management platform module when the activity is created
*/
private fun initSfbxModule() {
val appConsentTheme: AppConsentTheme =
AppConsentTheme.Builder(this.applicationContext).build()
val configuration: ACConfiguration = ACConfiguration.Builder()
.defineAppConsentTheme(appConsentTheme)
.setForceApplyGDPR(false)
.build()
AppConsentSDK.initialize(
"{APP_KEY}",
configuration
) { appConsentInitialized: AppConsent? ->
/*
To avoid certain problems, use the instance received by the onReady callback
This has been successfully initialized
*/
appConsent = appConsentInitialized
/*
Registers with CMP callback to know when the user
has given consent, or if an error has occurred
*/
appConsent!!.setOnPresentNoticeListener(object :
OnPresentNoticeListener {
override fun presentConsentGiven() {
/*
The user has given his consent
*/
}
override fun presentConsentError(error: Throwable?) {
/*
An error has occurred
*/
}
})
/*
Try to display the CMP according to certain rules.
*/
val isNoticeDisplayed = appConsent?.tryToDisplayNotice(false)
if (isNoticeDisplayed == false) {
/*
The user has already given consent;
The user is not part of an area subject to the application of GDPR;
etc.
*/
}
}
}
}
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.sfbx.appconsent.AppConsent;
import com.sfbx.appconsent.ui.AppConsentSDK;
import com.sfbx.appconsent.ui.AppConsentTheme;
import com.sfbx.appconsent.ui.listener.OnPresentNoticeListener;
import com.sfbx.appconsent.ui.model.ACConfiguration;
import kotlin.Unit;
public class MainActivity extends AppCompatActivity {
private AppConsent appConsent = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
If you use the CMP several times, avoid initializing it several times.
Use AppConsentSDK.getInstance to retrieve the already initialized instance, after checking whether it has already been initialized, or use the AppConsentSDK.initialize method.
*/
if(!AppConsentSDK.isSdkInitialized()){
initSfbxModule();
}else{
appConsent = AppConsentSDK.getInstance();
}
}
/*
Initializes the consent management platform module when the activity is created
*/
private void initSfbxModule() {
final AppConsentTheme appConsentTheme = new AppConsentTheme.Builder(this.getApplicationContext()).build();
ACConfiguration configuration = new ACConfiguration.Builder()
.defineAppConsentTheme(appConsentTheme)
.setForceApplyGDPR(false)
.build();
AppConsentSDK.initialize(
"{APP_KEY}",
configuration,
appConsentInitialized -> {
/*
To avoid certain problems, use the instance received by the onReady callback
This has been successfully initialized
*/
appConsent = appConsentInitialized;
/*
Registers with CMP callback to know when the user
has given consent, or if an error has occurred
*/
appConsent.setOnPresentNoticeListener(new OnPresentNoticeListener() {
@Override
public void presentConsentGiven() {
/*
The user has given his consent
*/
}
@Override
public void presentConsentError(@Nullable Throwable error) {
/*
An error has occurred
*/
}
});
/*
Try to display the CMP according to certain rules.
*/
final boolean isNoticeDisplayed = appConsent.tryToDisplayNotice(false);
if (!isNoticeDisplayed) {
/*
The user has already given consent;
The user is not part of an area subject to the application of GDPR;
etc.
*/
}
return Unit.INSTANCE;
});
}
}
- Kotlin
- Java
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.sfbx.appconsent.AppConsent
import com.sfbx.appconsent.tv.AppConsentSDK
import com.sfbx.appconsent.tv.AppConsentTVTheme
import com.sfbx.appconsent.tv.listener.OnPresentNoticeListener
import com.sfbx.appconsent.tv.model.ACConfiguration
class MainActivity : AppCompatActivity() {
private var appConsent: AppConsent? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
If you use the CMP several times, avoid initializing it several times.
Use AppConsentSDK.getInstance to retrieve the already initialized instance, after checking whether it has already been initialized, or use the AppConsentSDK.initialize method.
*/
if (!AppConsentSDK.isSdkInitialized()) {
initSfbxModule()
} else {
appConsent = AppConsentSDK.getInstance()
}
}
/*
Initializes the consent management platform module when the activity is created
*/
private fun initSfbxModule() {
val appConsentTheme: AppConsentTVTheme =
AppConsentTVTheme.Builder(this.applicationContext).build()
val configuration: ACConfiguration = ACConfiguration.Builder()
.defineAppConsentTheme(appConsentTheme)
.setForceApplyGDPR(false)
.build()
AppConsentSDK.initialize(
"{APP_KEY}",
configuration
) { appConsentInitialized: AppConsent? ->
/*
To avoid certain problems, use the instance received by the onReady callback
This has been successfully initialized
*/
appConsent = appConsentInitialized
/*
Registers with CMP callback to know when the user
has given consent, or if an error has occurred
*/
appConsent!!.setOnPresentNoticeListener(object :
OnPresentNoticeListener {
override fun presentConsentGiven() {
/*
The user has given his consent
*/
}
override fun presentConsentError(error: Throwable?) {
/*
An error has occurred
*/
}
})
/*
Try to display the CMP according to certain rules.
*/
val isNoticeDisplayed = appConsent?.tryToDisplayNotice(false)
if (isNoticeDisplayed == false) {
/*
The user has already given consent;
The user is not part of an area subject to the application of GDPR;
etc.
*/
}
}
}
}
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.sfbx.appconsent.AppConsent;
import com.sfbx.appconsent.tv.listener.OnPresentNoticeListener;
import kotlin.Unit;
public class MainActivity extends AppCompatActivity {
private AppConsent appConsent = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
Shows whether the SDK has already been initialized
*/
if (!com.sfbx.appconsent.tv.AppConsentSDK.isSdkInitialized()) {
initSfbxModule();
} else {
if (appConsent == null) {
/*
Retrieves the AppConsent instance or null if it has not yet been instantiated, for example
*/
appConsent = com.sfbx.appconsent.tv.AppConsentSDK.getInstance();
}
}
}
/*
Initializes the consent management platform module when the activity is created
*/
private void initSfbxModule() {
com.sfbx.appconsent.tv.AppConsentSDK.initialize(
"{APP_KEY}",
appConsentInitialized -> {
/*
To avoid certain problems, use the instance received by the onReady callback
This has been successfully initialized
*/
appConsent = appConsentInitialized;
/*
Registers with CMP callback to know when the user
has given consent, or if an error has occurred
*/
appConsent.setOnPresentNoticeListener(new OnPresentNoticeListener() {
@Override
public void presentConsentError(@NonNull Throwable error) {
/*
An error has occurred
*/
}
@Override
public void presentConsentGiven() {
/*
The user has given his consent
*/
}
});
/*
Try to display the CMP according to certain rules.
*/
final boolean isNoticeDisplayed = appConsent.tryToDisplayNotice(true);
if (!isNoticeDisplayed) {
/*
The user has already given consent;
The user is not part of an area subject to the application of GDPR;
etc.
*/
}
return Unit.INSTANCE;
});
}
}
3. Then use appConsent object
- Check if user gave consent
appConsent.consentGiven()
Return true
if consent is given, false
otherwise.
- Consent listener
Add Listener
appConsent.setOnPresentNoticeListener(object : OnPresentNoticeListener {
override fun presentConsentGiven() {
// ...
}
override fun presentConsentError(error: Throwable?) {
// ...
}
})
Remove Listener
appConsent.setOnPresentNoticeListener(null)
- Display CMP notice
// @return true if the notice display, false otherwise
appConsent.tryToDisplayNotice(false) // display CMP notice only if needed
appConsent.tryToDisplayNotice(true) // force to display CMP notice
info
tryToDisplayNotice(force : Boolean)
is a local method that only check cache. See checkForUpdate()
to fetch a notice update
- Consentable allowed
appConsent.consentableAllowed(1,0)
Return true
if consentable with id = 1
and consentableType = 0
is allowed, false
otherwise. The id
to pass is the iabId
of your purpose and the consentableType
is the type, e.g: purpose = 0
.
- Stack Allowed
appConsent.stackAllowed(1)
Return true
if stack with id = 1
is allowed, false
otherwise.
- Vendor allowed
appConsent.vendorAllowed(1)
Return true
if vendor with id = 1
is allowed, false
otherwise.
- Set consentable status
appConsent.setConsentableConsents(
mapOf(1 to ConsentStatus.ALLOWED, 2 to ConsentStatus.DISALLOWED),
object : AppConsentSetConsentableConsentsCallback {
override fun onSuccess() {
// ...
}
override fun onError(t: Throwable) {
// ...
}
}
)
Set consentables status, save it and send it to server.
- Check for update
appConsent.checkForUpdate(object : AppConsentUpdateCallback {
override fun onResult(updated: Boolean) {
// ...
}
override fun onError(t: Throwable?) {
// ...
}
})
Check if consent must be updated (new gvl version, new consentables...).
- Clear consents
appConsent.clearConsent()
Clear consents on mobile, but not on server.
- Set external data
val map = mapOf<String, Any>("externalId" to "abze23", "otherData" to "{\"name\": \"test\"}")
appConsent.setExternalData(map)
Set external data and send it to server.
- Get external data
val map: Map<String, Any> = appConsent.getExternalData()
4. Retrieve your consents
Your consents are saved in SharedPreferences
of your application. To know more about keys used to save your consents, please refer to the IAB documentation.
We also provide an additional key for Google Additionnal Consent IABTCF_AddtlConsent
returning a String.
5. Xchange
- Set xchange user data
appConsent.setXchangeUserData(
XChangeData.Builder()
.email("test@sfbx.io")
.build()
)
Save user data in cache, and when user give his consent, data are sent to server.