Install Brand Messenger Android SDK

Install the Brand Messenger Android SDK into your project

Prerequisites

Get your Company Key and Application ID

Contact Khoros Support for your Company Key and Application ID.

Requirements

  • Latest android studio
  • From version 1.3.0, the SDK requires application's compileSdkVersion and targetSdkVersion to be 33 or higher
  • The AGP version should be 7.4.2 or higher and gradle version 7.5 or higher.
  • The minimum android SDK version supported is 19. (v 1.14.5 onwards this is changed to 21)

Installation

Jitpack

The Brand Messenger Android SDK is distributed via a public repository.

Add JitPack repository to the end of the root build.gradle file:

allprojects {
    repositories {
        ...
        maven {
            url "https://jitpack.io"
        }
    }
 }

Add Brand Messenger to the module build.gradle:

dependencies {
    implementation 'com.github.lithiumtech.android-brandmessenger-sdk-dist:brandmessengercore:<version>'
    implementation 'com.github.lithiumtech.android-brandmessenger-sdk-dist:brandmessengerui:<version>'
}

Maven central

Version 1.15.0 onwards the SDK is distributed via mavenCentral().

To get started, add mavenCentral() to your project-level build.gradle.

allprojects {
    repositories {
        ...
        mavenCentral()
    }
 }

Add the following dependencies to module(app) level build.gradle

dependencies {
...
implementation 'com.khoros.android-brandmessenger-sdk:brandmessengercore:1.15.0'
implementation 'com.khoros.android-brandmessenger-sdk:brandmessengerui:1.15.0'
}

Sync the project, build, and run.

Pre-built customizable chat UI

This section will guide you in using our pre-built chat UI in your Android app.

  1. Add your Brand Messenger Company Key and Application ID to your manifest. Contact Khoros Support for the Company Key and Application ID:
<meta-data android:name="com.brandmessenger.company.key"
           android:value="<YOUR_BRAND_MESSENGER_COMPANY_KEY>" />

<meta-data android:name="com.brandmessenger.application.key"
           android:value="<YOUR_BRAND_MESSENGER_APP_ID>" />
  1. For enabling push notifications, you must have a Firebase account. Sign up to Firebase console and create your application with app package name
    and generate a push notification Google JSON service file. Then, place the file in your application under the app folder.

  2. Contact Khoros Support with the GCM/FCM server key to update it on the push notification server.

  3. Add the following in Gradle Android target:

android {

        packagingOptions {           
           exclude 'META-INF/DEPENDENCIES'      
           exclude 'META-INF/NOTICE'         
           exclude 'META-INF/LICENSE'      
           exclude 'META-INF/LICENSE.txt'    
           exclude 'META-INF/NOTICE.txt' 
           exclude 'META-INF/ECLIPSE_.SF'
           exclude 'META-INF/ECLIPSE_.RSA'
         }    
    }

AndroidManifest

Add the following Permissions, Activities, Services, and Receivers in your androidmanifest.xml:

📘

Add meta-data, Activities within application Tag

📘

If using tools:node="replace" tag for any component, metadata or permissions, make sure to define the tag within your </manifest> tag as: xmlns:tools="http://schemas.android.com/tools"

Add the metadata as shown below:

<!-- Brand Messenger Company Key -->
<meta-data android:name="com.brandmessenger.company.key"
           android:value="<YOUR_BRAND_MESSENGER_COMPANY_KEY>" />

<!-- Brand Messenger App ID -->
<meta-data android:name="com.brandmessenger.application.key"
           android:value="<YOUR_BRAND_MESSENGER_APP_ID" />

<!-- Launcher white Icon -->
<meta-data android:name="com.brandmessenger.core.ui.notification.smallIcon"
           android:resource="YOUR_LAUNCHER_SMALL_ICON" /> 

<!-- Notification color -->
<meta-data android:name="com.brandmessenger.core.ui.notification.color"
           android:resource="YOUR_NOTIFICATION_COLOR_RESOURCE" /> 

<!-- NOTE: Do NOT change this, it should remain same i.e 'com.package.name' -->            
<meta-data android:name="com.package.name" 
           android:value="${applicationId}" />

Add the Activity as shown below:

<activity android:name="com.brandmessenger.core.ui.conversation.activity.ConversationActivity"
            android:configChanges="keyboardHidden|screenSize|locale|smallestScreenSize|screenLayout|orientation"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:parentActivityName=".MainActivity"
            android:theme="@style/KBMTheme"
            tools:node="replace">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>

📘

Replace the parent activity with your app's parent activity.

Your final AndroidManifest file should look something like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mobicomkit.sample"
    android:versionCode="1"
    android:versionName="1.0">

    <application
        android:name=".MainApplication"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        
      <activity
            android:name=".MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.brandmessenger.core.ui.conversation.activity.ConversationActivity"
            android:configChanges="keyboardHidden|screenSize|locale|smallestScreenSize|screenLayout|orientation"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:parentActivityName=".MainActivity"
            android:theme="@style/KBMTheme"
            tools:node="replace">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>

        <!-- Brand Messenger Company Key -->
        <meta-data android:name="com.brandmessenger.company.key"
           android:value="<YOUR_BRAND_MESSENGER_COMPANY_KEY>" />

        <!-- Brand Messenger App ID -->
        <meta-data android:name="com.brandmessenger.application.key"
           android:value="<YOUR_BRAND_MESSENGER_APP_ID" />

        <!-- Launcher white Icon -->
        <meta-data android:name="com.brandmessenger.core.ui.notification.smallIcon"
           android:resource="YOUR_LAUNCHER_SMALL_ICON" /> 

        <!-- Notification color -->
        <meta-data android:name="com.brandmessenger.core.ui.notification.color"
           android:resource="YOUR_NOTIFICATION_COLOR_RESOURCE" /> 

        <!-- NOTE: Do NOT change this, it should remain same i.e 'com.package.name' -->            
        <meta-data android:name="com.package.name" 
           android:value="${applicationId}" /> 
</manifest>

ProGuard Setup

Add the following if you are using ProGuard:

#keep json classes                
-keepclassmembernames class * extends com.brandmessenger.commons.json.JsonMarker {
    !static !transient <fields>;
}
-keepclassmembernames class * extends com.brandmessenger.commons.json.JsonParcelableMarker {
    !static !transient <fields>;
}
-keep class com.brandmessenger.** {
    !static !transient <fields>;
}
 #GSON Config          
-keepattributes Signature          
-keep class sun.misc.Unsafe { *; }           
-keep class com.google.gson.examples.android.model.** { *; }            
-keep class org.eclipse.paho.client.mqttv3.logging.JSR47Logger { *; } 
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-dontwarn android.support.v4.**
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-keep class com.google.gson.** { *; }

Below is the list of libraries used in the Brand Messenger SDK:

implementation 'de.hdodenhof:circleimageview:3.1.0' //for circular images
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'//for image cropping
implementation 'com.github.bumptech.glide:glide:4.12.0' //for loading images
implementation 'com.google.android.material:material:1.0.0'

implementation 'androidx.constraintlayout:constraintlayout:2.0.4'//constraint layout
api 'androidx.appcompat:appcompat:1.3.0'
api "com.google.code.gson:gson:2.8.6" //JSON parsing library

api "com.google.firebase:firebase-messaging:22.0.0" //for FCM notification 
api "com.google.android.gms:play-services-maps:17.0.1" //for google maps 
api "com.google.android.gms:play-services-location:18.0.0" //for location services

Android 13 Support

Note: Skip this section if you are not targeting Android 13 and above.

To support android-13, make sure to add the following to AndroidManifest.xml:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

You can override the following strings to customise the permission texts which appear on screen:

<string name="com.kbm.storage_permission">Storage permission are needed to access</string>  
<string name="com.kbm.post_notification_permission">Notification permissions are needed to receive notifications</string>  
<string name="com.kbm.location_permission">Location permission are needed to access</string>  
<string name="com.kbm.phone_camera_permission">Camera permission are needed to access</string>  
<string name="com.kbm.record_audio">Audio recording permission needed</string>  
<string name="com.kbm.camera_audio_permission">Camera and record audio permission are needed to access</string>

<string name="com.kbm.phone_camera_permission_not_granted">Permissions were not granted for Camera</string><string name="com.kbm.record_audio_permission_not_granted">Permissions were not granted for Audio recording</string>  
<string name="com.kbm.audio_or_camera_permission_not_granted">Permissions were not granted for Camera or Audio recording</string>  
<string name="com.kbm.post_notification_permission_not_granted">Permissions were not granted for receiving notifications</string>  
<string name="com.kbm.location_permission_not_granted">Permissions were not granted for Location</string>  
<string name="com.kbm.storage_permission_not_granted">Permissions were not granted for Storage</string>

<string name="com.kbm.post_notification_permission_granted">Notification permissions have been granted</string>  
<string name="com.kbm.storage_permission_granted">Storage Permissions have been granted</string>  
<string name="com.kbm.location_permission_granted">Location Permissions has been granted</string>  
<string name="com.kbm.phone_camera_permission_granted">Camera permission has been granted</string>  
<string name="com.kbm.record_audio_permission_granted">Audio Record permissions has been granted</string>  
<string name="com.kbm.phone_camera_and_audio_permission_granted">Camera and audio permissions has been granted</string>