Skip to content

Contextual (AndroidX) Setup

You can find an example app with the sdk integrated here

Prerequisites

  1. Your App must be targeted for at least Lollipop (21) and above;
  2. Your app’s compileSdkVersion must be set to 28 or higher
  3. Contextual v2 uses AndroidX, so your app must use AndroidX as well (Migration instructions).

    This version of Contextual is recommended for all apps using AndroidX that don't specifically need Android v19-v21, if you need to support versions 19-21 please go to Pointz Legacy.

  4. Contextual uses Java 1.8 features, please make sure your app uses it as well:
1
2
3
4
5
6
7
8
9
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

Step 1 - Adding Contextual to your gradle files

These are the two gradle files we need you to make changes

Step 2 - Project level build.gradle

Please add the Contextual repository to your build.gradle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
allprojects {
    repositories {
        maven {
            url "https://repo.pointzi.com/sdk/pointzi/"
        }
        google()
        mavenCentral()

    }
}

By default, new Android Studio projects specify Google's Maven repository, and the Maven central repository as repository locations in the project's settings.gradle file in dependencyResolutionManagement block, as shown below

1
2
3
4
5
6
7
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

Remove dependencyResolutionManagement block from setting.gradle if Contextual repository is added to project level build.gradle. *For new project contextual repository should be added to settings.gradle only shown as below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url "https://repo.pointzi.com/sdk/pointzi/"
        }
    }
}

Step 3 - Module (app) level build.gradle

This will link the Contextual SDK with your app.

You need to add this either to the root of your app's build.gradle or under the android {} task

1
2
3
dependencies {
    implementation (group: "com.pointzi", name: "pointzi", version: "2.+")
}

Contextual UI is based on Google's Material Components library. Please ensure your app's theme inherits from Theme.MaterialComponents or its subthemes.

Also, please, check if your app uses a version eqal or more recent to 1.1.0

1
2
3
dependencies {
    implementation (group: "com.google.android.material", name: "material", version: "1.1.0")
}

You need to make sure that inside your app/res/values/styles.xml (or equivalent) the parent of AppTheme is part of the Theme.MaterialComponents theme. Here is an example from the Wikipedia's app:

1
2
3
4
5
6
   <style name="BaseAppTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> 
        <...>
    </style>
    <style name="AppTheme" parent="BaseAppTheme">
        <...>
    </style>

(If you are having issues with this please check instructions here, specially step 4)

Integrating Contextual to your app

Set your Contextual AppKey in your AndroidManifest.xml file

Under the application tag, add the following meta-data tag replacing APP_KEY with your app key:

1
2
3
4
5
6
7
    <application
        android:name=".MainApplication">

        <meta-data
            android:name="com.pointzi.APP_KEY"
            android:value="APP_KEY" />
    </application>

Identifying your users

At this point Contextual is fully integrated on you app, but to make it easier to identify your users and use the full capabilities of the Contextual SDK you can use the following method at any part of your code after performing the integration.

Java:

1
Pointzi.setUserId("BestUserEver#24");

Kotlin:

1
Pointzi.setUserId("BestUserEver#24")

Last update: 2022-06-17