Android SDK

This is a step by step guide to include Conscent.ai Plugin in your app. This plugin is developed in Kotlin and supports both Java and Kotlin languages.

Pre-Requisites

Conscent.ai Android SDK supports API 21 (Android 5.0) and above. Please ensure the minSdkVersion is in the app's build.gradle file reflects the same.

In case of an error for Kotlin not enabled - Enable Kotlin for Project.

In case of an error in Manifest merging - Merge Manifest as per Android Studio support or include the below line inside your application tag in the Android Manifest file.

tools:replace="android:icon,android:roundIcon" 

To integrate SDK, you need to enable the below-listed dependencies:

  • Data Binding

  • View Binding

  • Jetpack Compose

Permissions

Add the following permissions to the AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Installation

You can download and add AAR File from here, which needs to be included in your Module libs directory, and tell gradle to install it like this:

Following files are required to be added.
dependencies {
    implementation fileTree(include: [ '*.aar'], dir: 'libs')
}

Dependencies

In root level (project level) build.gradle, add classpath, and maven:

dependencies {
    classpath 'com.google.gms:google-services:[latest-version]'
    // Add the Crashlytics Gradle plugin
    classpath 'com.google.firebase:firebase-crashlytics-gradle:[latest-version]'
}

In your application build.gradle file, include dependency as below with the latest versions:

dependencies{
// Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.9'
// Coroutines    
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
// Browser   
     implementation 'androidx.browser:browser:1.5.0'
     implementation 'com.google.android.gms:play-services-base:[latest-version]'
     implementation (platform("com.google.firebase:firebase-bom:[latest-version]"))
     implementation ("com.google.firebase:firebase-analytics-ktx")
     implementation ("com.google.firebase:firebase-crashlytics-ktx")
     implementation 'com.squareup.picasso:picasso:[latest-version]'
     implementation "androidx.swiperefreshlayout:swiperefreshlayout:[latest-version]"
     
// compose
def composeBom = platform('androidx.compose:compose-bom:2023.04.01')
implementation composeBom
androidTestImplementation composeBom

implementation "androidx.compose.material:material:1.4.3"
implementation 'androidx.compose.ui:ui'
// Android Studio Preview support
implementation 'androidx.compose.ui:ui-tooling-preview'
debugImplementation 'androidx.compose.ui:ui-tooling'
// Optional - Integration with activities
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.1'
implementation 'androidx.compose.ui:ui-text-google-fonts:1.5.0-beta02'

// Contains the core Credential Manager functionalities including password
// and passkey support.
implementation("androidx.credentials:credentials:1.3.0-alpha01")
// Provides support from Google Play services for Credential Manager,
// which lets you use the APIs on older devices.
implementation("androidx.credentials:credentials-play-services-auth:1.3.0-alpha01")
implementation("com.google.android.libraries.identity.googleid:googleid:1.1.0")
implementation ("com.google.firebase:firebase-auth-ktx:[latest-version]")
}

Initialize SDK

In your application or root activity class's method onCreate, pass these fields to be used in your app.

  • applicationContext - Pass your application context.

  • yourClientId - Pass your clientId received from Conscent.ai.

  • yourAccentColor - Pass your accentColor for the app.

  • Mode - configuration testing of different environments available.

  • APP_MODE - used for checking the debug and production environment of the app.

Api Mode can be set as :
    ConscentConfiguration.MODE.SANDBOX
    ConscentConfiguration.MODE.PRODUCTION

APP_MODE can be set as : 
    ConsCentConfiguration.APP_MODE.DEBUG 
    ConsCentConfiguration.APP_MODE.PROD

If APP_MODE is DEBUG, all errors will be shown as Toast messages and Logs.

If APP_MODE is PROD, only logs will be available for critical errors like Network unavailability, wrong client_id, and wrong content_id.

class TestingApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        ConscentWrapper.configure(
            application = this,
            clientId = "5f92a62013332e0f667794dc",
            appMode = ConscentConfiguration.APP_MODE.DEBUG,
            apiMode = ConscentConfiguration.MODE.SANDBOX,
        )
    }
}

Pass the client ID received from Conscent.ai dashboard

Initialize the paywall

In order to ensure that the Conscent.ai Paywall appears on the targeted pages and the deep insights and analytics are collected optimally you need to implement the following method on all the content/article pages.

To have more control over the content flow, create an instance of the Conscent class inside your activity onCreate method for each unique contentId(recommended).

Use the below-described method:

val instance = ConscentWrapper.getConscentInstance(
            callingActivity = yourCallingActivity,
            parentView = yourParentView,
            containerView = yourContainerView,
            popUpContainer = yourPopUpContainerView,
            onConscentListener = onConscentListener,
            contentId = contentId,
            title = contentTitle,
            categories= arrayListOf("categorie1","categorie2","categorie3"),
            sections = arrayListOf("section","section1","section3"),
            tags = arrayListOf("premium"),
            url = ContentUrl,
            authorName = authorName,
            publicationDate = "2024-07-17T11:57:27.312Z"
        )
//To display the registration paywall 
RegistrationPaywall.initRegistrationPaywall()
//To display the paywall       
Paywall.initRegularPaywall()
//To display the metered banner
MeterBanner.initMeterBanner()

Note: Include the AAR files of respective paywalls and banners before calling above functions.

To set the scroll depth on the content page:

instance.scrollDepth = scrollY

In case of Fragment, call the below method inside onDestoyView()-

instance.onDestroy()

You can implement OnConscentListener in your activity and then pass it as a reference.

To check if an article/content is free/paid or payment needs to be done, in your class, use as below sample: Parameters detail can be checked below for more information.

instance.checkContentAccess(
     contentId
    )

Call checkContentAccess method on override onNewIntent method in Activity Class.

Call the below function and pass the userId, after the user has logged in:

PluginPreferences.setClientUserId("Your_User_Id")
Login Functionality

Call this method to invoke our Login System

ConscentWrapper.INSTANCE?.onSSOLogin(
        consCentLoginCallbacks = object : ConsCentLoginCallbacks {
         override fun onLoginSuccess(
         message: String,
                    userId: String,
                    authToken: String
                    ) {
            Log.d(TAG, " $message, $userId, $authToken ")
                    }

        override fun onLoginFailure(message: String, errorCode: String) {
            Log.d(TAG, "$message, $errorCode ")
                    }

                },
        clientActivity = this@yourCallingActivity,
            )

Fetch User-details Method

Call this method to show User Profile Page:

ConscentWrapper.INSTANCE?.openUserDetails(
    clientActivity = this@yourCallingActivity,
    consCentUserProfileCallbacks = object: ConsCentUserProfileCallbacks {
        override fun userLogoutSuccess(message: String, statusCode: String) {
            Log.d(
                TAG,
                "$message $statusCode"
            )
        }

        override fun userLogoutFailed(message: String, statusCode: String) {
            Log.e(
                TAG,
                "$message $statusCode"
            )
        }

        override fun userDeleteAccountSuccess(message: String, statusCode: String) {
            Log.d(
                TAG,
                "$message $statusCode"
            )
        }

        override fun userDeleteAccountFailed(message: String, statusCode: String) {
            Log.e(
                TAG,
                 "$message $statusCode"
            )
        }

        override fun userNotLoggedIn(message: String, statusCode: String) {
            Log.e(
                TAG,
                "$message $statusCode"
            )
        }

    }
)

Call this method to fetch user-details:

ConscentWrapper.INSTANCE?.getUserDetails(
userDetailSuccess = { userDetails->
Log.d(TAG, "showUserDetails: $userDetails")
},
failure = {
Log.e(TAG, "showUserDetails: $it")
})

Logout the User:

ConscentWrapper.INSTANCE?.onSSOLogOut(
                this@yourCallingActivity,
                consCentLogoutCallbacks = object : ConsCentLogoutCallbacks {
                    override fun onLogOutSuccess(message: String, successCode: String) {
                        Log.d(TAG, "$message  $successCode")
                    }

                    override fun onLogOutFailure(message: String, errorCode: String) {
                        Log.e(TAG, "$message  $errorCode")
                    }

                },
            )

Demo App: Link

Last updated