Native Android SDK

REVE Chat’s Android SDK can be seamlessly integrated with your mobile apps and enable your team to deliver in-app messaging to your app users for better engagement and customer support.

This documentation shows you how to embed REVE Chat Android SDK in an Android application and get started in a few minutes.

Minimum Requirements

  1. Android Studio

  2. Minimum SDK version should be 24 or above

  3. SDK Version: 3.2.2

Android SDK Integration Process

Step 1

To integrate Android SDK with your mobile app, please follow the below mentioned steps. Based on gradle version follow either steps in (a) or (b)

  1. If gradle version is ( 7.X to 8.0 ) , add following repositories in project gradle file ( build.gradle )

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        mavenLocal()
        google()
        maven {
            url "https://maven.iptelephony.revesoft.com/artifactory/libs-release-local/"
        }
        maven {// for revesoft cpp
            url "https://jfrog-artifact.revechat.com/artifactory/artifactory/"
        }
        maven { url "https://jitpack.io" }
    }
}
  1. If gradle version is 8.X to latest, add following repositories in settings.gradle

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.google.com/' }
        maven {
            url "https://jfrog-artifact.revechat.com/artifactory/artifactory/"
        }
        maven {
            url "https://maven.iptelephony.revesoft.com/artifactory/libs-release-local/"
        }
    }
}

Step 2

Add Design support library and REVE Chat Android SDK as dependency in your App level build.gradle file :


buildFeatures {
       dataBinding  true
       viewBinding true
       buildConfig = true
   }


dependencies {
   implementation('com.revesoft.revechatsdk:revechatsdk:3.2.2')
}

Step 3

Add following following method in your Main Activity and call this from onCreate() method.

Code for JAVA

private void initiateReveChat() {
    // Initializing with account id
    ReveChat.init(accountId);

    // Create visitor info
    VisitorInfo visitorInfo = new VisitorInfo.Builder()
            .name(userName) // set name
            .email(userEmail)
            .phoneNumber(userPhone)
            .build();

    // visitorInfo.setAccessToken(accessToken); // set access token if any

    ReveChat.setVisitorInfo(visitorInfo);

    ReveChat.setAppBundleName(BuildConfig.APPLICATION_ID);
    ReveChat.setAppVersionNumber(BuildConfig.VERSION_NAME);

    Intent intent = new Intent(this, REVEChatApiService.class);
    startService(intent);
}

Code for KOTLIN

private fun initiateReveChat() {
        ReveChat.init(accountId)

        //create visitor info
        val visitorInfo: VisitorInfo = VisitorInfo.Builder()
            .name(userName) // set name
            .email(userEmail)
            .phoneNumber(userPhone)
            .build()


        ReveChat.setVisitorInfo(visitorInfo)

        ReveChat.setAppBundleName(BuildConfig.APPLICATION_ID)
        ReveChat.setAppVersionNumber(BuildConfig.VERSION_NAME)
        startService(Intent(this, REVEChatApiService::class.java))
    }

Step 4

Call following method when you want to open the chat window ( e.g. on implementation of setOnClickListener() of chat button )

// Java

   private void openChatWindow() {
        startActivity(new Intent(this, ReveChatActivity.class));
    }
 // Kotlin
 private fun openChatWindow() {
      startActivity(Intent(this, ReveChatActivity::class.java))
 }

Step 5

Stop REVEChatApiService from MAIN/LAUNCHER Activity’s onDestroy() method

// for Java

@Override
protected void onDestroy() {
       super.onDestroy();
       if (!WebRTCHandler.INSTANCE.isWebRTCCallRunning())
           stopService(new Intent(this, REVEChatApiService.class));
   }

// for Kotlin

override fun onDestroy() {
       super.onDestroy()
       if (!REVEChatApiService.isCallRunning())
           stopService(Intent(this, REVEChatApiService::class.java))

   }

Step 5

If Application class is not added, then please implement it and add in manifest file

// In manifest file, application tag add your Application class ( e.g. in below example 
implmetation of Application class MyApplication )

<application
android:name=".MyApplication" />

Need to add below line in onCreate() method

  1. ProcessLifecycleOwner.get().getLifecycle().addObserver(REVEChatAppLifecycleObserver.INSTANCE) // need to call from onCreate() method

import android.app.Application;
import androidx.lifecycle.ProcessLifecycleOwner;
import com.google.firebase.FirebaseApp;
import com.revesoft.revechatsdk.utils.REVEChatAppLifecycleObserver;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        ProcessLifecycleOwner.get().getLifecycle().addObserver(REVEChatAppLifecycleObserver.INSTANCE);
    }
}

import android.app.Application
import androidx.lifecycle.ProcessLifecycleOwner
import com.google.firebase.FirebaseApp
import com.revesoft.revechatsdk.utils.REVEChatAppLifecycleObserver

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        ProcessLifecycleOwner.get().lifecycle.addObserver(REVEChatAppLifecycleObserver.INSTANCE)
    }
}

Step 6

Push Notification implementation

(i) in project gradle file add below

dependencies {
        classpath 'com.google.gms:google-services:4.4.2'
    }

(ii) in app gradle file add below dependency

dependencies {
    // firebase push
    implementation 'com.google.firebase:firebase-messaging:24.0.3' // Update version if necessary    
}

(iii) in application class onCreate() method, add below code

FirebaseApp.initializeApp(this);

(iv) create a class extending FirebaseMessagingService if not already there. In this class add below necessary codes to implement push notification. Need to use PushMessageProcessor class to send necessary information to SDK.

Below code block shows implementation in Java

public class MessagingService extends FirebaseMessagingService {

    private PushMessageProcessor pushMessageProcessor;

    @Override
    public void onCreate() {
        super.onCreate();
        pushMessageProcessor = new PushMessageProcessor(this);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        pushMessageProcessor.handlePushMessage(new JSONObject(remoteMessage.getData()));
    }


    @Override
    public void onNewToken(String refreshedToken) {
        super.onNewToken(refreshedToken);
        pushMessageProcessor.onNewToken(refreshedToken);
    }
 } 

Below code block shows implementation in Kotlin

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.revesoft.revechatsdk.message.processor.PushMessageProcessor;
import org.json.JSONObject;

public class MessagingService extends FirebaseMessagingService {
  
    private PushMessageProcessor pushMessageProcessor;

    @Override
    public void onCreate() {
        super.onCreate();
    
        pushMessageProcessor = new PushMessageProcessor(this);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
       
        pushMessageProcessor.handlePushMessage(new JSONObject(remoteMessage.getData()));
    }

    @Override
    public void onNewToken(String refreshedToken) {
        super.onNewToken(refreshedToken);
        
        pushMessageProcessor.onNewToken(refreshedToken);
    }
}

(v) declare the class in Manifest file, if not already declared

<service
android:exported ="false"
android:name=".MessagingService">

    <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
</service> 

(vi) Add Firebase Service Account JSON Configuration in Agent Dashboard (https://app.revechat.com/)

Go to Settings -> Chat Widgets . Select the chat widget, then go to code snippet. In android section, copy paste json data.

Step 7

In the gradle.properties file add following lines

android.useAndroidX=true
android.enableJetifier=true

Step 8

Proguard Configuration

In your proguard configuration file add below:


-keep class org.webrtc.** { *; }
-keep class org.webrtc.voiceengine.** { *; }
-dontwarn org.webrtc.**

-keep class com.revesoft.revechatsdk.**{*;}
-keep interface com.revesoft.revechatsdk.* { *; }
-keep enum com.revesoft.revechatsdk.* { *; }
-dontwarn com.revesoft.revechatsdk.**

# Preserve generic type information for Gson
-keepattributes Signature

# Keep all classes and fields with generic types
-keepclassmembers,allowobfuscation class * {
    *;
}

# Keep Gson type adapters and serializers/deserializers
-keep class * extends com.google.gson.TypeAdapter
-keep class * extends com.google.gson.JsonSerializer
-keep class * extends com.google.gson.JsonDeserializer

# Keep any classes that use Gson with generics
-keep class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

GitHub sample application Link: AndroidReveChatSDKTestApp

Last updated

Was this helpful?