Android & Android TV: Basic implementation

Android & Android TV: Basic implementation

Android basic implementation

To implement the Android version, the first step is to import the sibbo-cmp-android-library-inapp.aar library that we provide, into the Android Studio project:

- We copy it to /app/libs/
- In the gradle of the project we must add the following code (if it does not exist):
  1. buildscript {
  2.     ext.kotlin_version = '1.8.10'
  3.     repositories {
  4.         google()
  5.         jcenter()
  6.     }
  7.     dependencies {
  8.           ....
  9.           ....
  10.           classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version 
  11.      }
  12. }

The next step is to add to the start of the gradle app (if it doesn't exist):
  1. apply plugin: 'com.android.application'
  2. apply plugin: 'kotlin-android'

    and as dependencies:
    1. implementation 'androidx.appcompat:appcompat:1.6.1'
    2. implementation 'androidx.preference:preference-ktx:1.2.0'
    3. implementation 'androidx.core:core-ktx:1.10.1'
    4. implementation 'com.google.code.gson:gson:2.9.0'
    5. implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    6. implementation ‘androidx.webkit:webkit:1.7.0'
    7. implementation files(‘libs/libs/sibbo-cmp-android-library-inapp.aar’)

    In the assets directory of the application, you must create a folder called web and inside this folder called src -> assets/web/src. In this path you must create a file called index.html
    with the following code:
    1. <html>
    2. <head>
    3.     <meta charset="UTF-8" />
    4.     <meta name="viewport"
    5.           content="width=device-width, user-scalable=device-height, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
    6.     <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    7.     <title>Sibbo</title>
    8.     <script src="https://cmp.sibbo.net/v2.2/sibbo-cmp-core.js" charset="utf-8"></script>
    9.     <script src="{{URL}}"  charset="utf-8"></script>
    10.     <script src="js/main.js"></script>
    11. </head>
    12. <body>
    13. </body>
    14. </html>

    You have to replace the URL {{URL}} with the URL that we will provide and that carries the CMP configuration.

    It is mandatory to add to the app that hosts the CMP, a link or button with the text Cookies or Cookies configuration, which triggers the method
    1. CMP.CMP.tryShowConsentTool(true);
    This method will refloat the CMP.

    There is a CMP.setOnTryOpenListener listener, see Methods section in Android / AndroidTV, which returns true if the consent interface has been shown and false if it has not.

    To make use of the library in the main Activity of the App, you have to import it and initialize the CMP component, in the onCreate as indicated:

    Example in Kotlin

    1. import com.sibboventures.sibbocmp2.ConsentHelper

    2. // The first parameter is the activity context
    3. // The second parameter showOnInit indicates whether you want to try to open the CMP when initializing it, its default value is true
    4. val CMP: ConsentHelper = ConsentHelper(YourContext, showOnInit: true)

    5. // Optional listeners
    6. CMP.setOnTryOpenListener { success ->
    7.       // Your code
    8. }

    9. CMP.setOnCloseListener {
    10.       // Your code
    11. }

    12. // The tryShowConsentTool method can be called to force the CMP to open
    13. CMP.tryShowConsentTool(true) 

    Example in Java

    1. import com.sibboventures.sibbocmp2.ConsentHelper

    2. // The first parameter is the activity context
    3. // The second parameter showOnInit indicates whether you want to try to open the CMP when initializing it, its default value is true
    4. private ConsentHelper CMP = new ConsentHelper(YourContext, true);

    5. // Optional listeners
    6. CMP.setOnTryOpenListener( success -> {
    7.       // Your code
    8. });

    9. CMP.setOnCloseListener ( ( ) -> {
    10.       // Your code
    11. });

    12. // The tryShowConsentTool method can be called to force the CMP to open
    13. CMP.tryShowConsentTool(true); 
    In the previous code, the object of the ConsentHelper class is created and the Application context is passed as an argument, and optionally a boolean that indicates whether the CMP should try to display itself when initialized, by default its value is true.

    You always have to call
    1. CMP.tryShowConsentTool(false); 
     at startup so that the CMP interface is displayed if necessary (outdated consent string, for example).

    It is not necessary to give write or storage permissions, but the library, being external to your app, must be given proguard permissions so that during compilation and obfuscation it does not lose the writing paths since the preferences are saved in the package the main app.

    In summary, you have to add the root of the sdk to the proguard-rules:
    1. -keep interface com.sibboventures.** { *; }
    2. -keep class com.sibboventures.** { *; }

    For the integration of the CMP with programmatic advertising, see the section Android / AndroidTV methods.

    To implement the CMP on Android TV, you must send us the Package name of the app. In this way we can include it in our whitelist. Otherwise, at the end of the deployment process, you will receive a message in the Android Studio console that the app is not validated.

    AndroidTV basic implementation

    To implement the Android TV version, the first step is to import the sibbo-cmp-android-library-inapp.aar library that we provide, into the Android Studio project:

    - We copy it to /app/libs/
    - In the gradle of the project we must add the following code (if it does not exist):

    1. buildscript {
    2.     ext.kotlin_version = '1.8.10'
    3.     repositories {
    4.         google()
    5.         jcenter()
    6.     }
    7.     dependencies {
    8.           ....
    9.           ....
    10.           classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version 
    11.      }
    12. }

    The next step is to add to the start of the gradle app (if it doesn't exist):
    1. apply plugin: 'com.android.application'
    2. apply plugin: 'kotlin-android'

      and as dependencies:
      1. implementation 'androidx.appcompat:appcompat:1.6.1'
      2. implementation 'androidx.preference:preference-ktx:1.2.0'
      3. implementation 'androidx.core:core-ktx:1.10.1'
      4. implementation 'com.google.code.gson:gson:2.9.0'
      5. implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
      6. implementation ‘androidx.webkit:webkit:1.7.0'
      7. implementation files(‘libs/libs/sibbo-cmp-android-library-inapp.aar’)

      In the assets directory of the application, you must create a folder called web and inside this folder called src -> assets/web/src. In this path you must create a file called index.html
      with the following code:
      1. <html>
      2. <head>
      3.     <meta charset="UTF-8" />
      4.     <meta name="viewport"
      5.           content="width=device-width, user-scalable=device-height, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
      6.     <meta http-equiv="X-UA-Compatible" content="ie=edge" />
      7.     <title>Sibbo</title>
      8.     <script src="https://cmp.sibbo.net/v2.2/sibbo-cmp-core-tv.js" charset="utf-8"></script>
      9.     <script src="{{URL}}"  charset="utf-8"></script>
      10.     <script src="js/main.js"></script>
      11. </head>
      12. <body>
      13. </body>
      14. </html>

      You have to replace the URL {{URL}} with the URL that we will provide and that carries the CMP configuration.

      It is mandatory to add to the app that hosts the CMP, a link or button with the text Cookies or Cookies configuration, which triggers the method
      1. CMP.CMP.tryShowConsentTool(true);
      This method will refloat the CMP.

      There is a CMP.setOnTryOpenListener listener, see Methods section in Android / AndroidTV, which returns true if the consent interface has been shown and false if it has not.

      To make use of the library in the main Activity of the App, you have to import it and initialize the CMP component, in the onCreate as indicated:

      Example in Kotlin

      1. import com.sibboventures.sibbocmp2.ConsentHelper

      2. // The first parameter is the activity context
      3. // The second parameter showOnInit indicates whether you want to try to open the CMP when initializing it, its default value is true
      4. val CMP: ConsentHelper = ConsentHelper(YourContext, showOnInit: true)

      5. // Optional listeners
      6. CMP.setOnTryOpenListener { success ->
      7.       // Your code
      8. }

      9. CMP.setOnCloseListener {
      10.       // Your code
      11. }

      12. // The tryShowConsentTool method can be called to force the CMP to open
      13. CMP.tryShowConsentTool(true) 

      Example in Java

      1. import com.sibboventures.sibbocmp2.ConsentHelper

      2. // The first parameter is the activity context
      3. // The second parameter showOnInit indicates whether you want to try to open the CMP when initializing it, its default value is true
      4. private ConsentHelper CMP = new ConsentHelper(YourContext, true);

      5. // Optional listeners
      6. CMP.setOnTryOpenListener( success -> {
      7.       // Your code
      8. });

      9. CMP.setOnCloseListener ( ( ) -> {
      10.       // Your code
      11. });

      12. // The tryShowConsentTool method can be called to force the CMP to open
      13. CMP.tryShowConsentTool(true); 
      In the previous code, the object of the ConsentHelper class is created and the Application context is passed as an argument, and optionally a boolean that indicates whether the CMP should try to display itself when initialized, by default its value is true.

      You always have to call
      1. CMP.tryShowConsentTool(false); 
       at startup so that the CMP interface is displayed if necessary (outdated consent string, for example).

      It is not necessary to give write or storage permissions, but the library, being external to your app, must be given proguard permissions so that during compilation and obfuscation it does not lose the writing paths since the preferences are saved in the package the main app.

      In summary, you have to add the root of the sdk to the proguard-rules:
      1. -keep interface com.sibboventures.** { *; }
      2. -keep class com.sibboventures.** { *; }

      For the integration of the CMP with programmatic advertising, see the section Android / AndroidTV methods.

      To implement the CMP on Android TV, you must send us the Package name of the app. In this way we can include it in our whitelist. Otherwise, at the end of the deployment process, you will receive a message in the Android Studio console that the app is not validated.