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
Android Studio
Minimum SDK version should be 24 or above
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)
If gradle version is ( 7.X to 8.0 ) , add following repositories in project gradle file ( build.gradle )
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 )
// 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
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);
}
}
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
-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>;
}