Android SDK

Overview

Ertc SDK is secure, easy to integrate, deploy and manage.

Following principles are followed during development

Modularity: Code is segregated into multiple modules and follow chain of responsibility model

Ease of Integration: Maven artifacts can be downloaded from a public hosted url . ERTC sdk can be integrated into any mobile app within minutes

Scalability: SDK is highly scalable and can support Enterprise traffic

Built on Latest Tech Stack

Data ownership: SDK provides a data layer to effectively manage and control data

Firebase powered by Google: Highly reliable and scalable

Reactive using RxAndroid

Features

  • Individual messages
  • Push notifications
  • Text, Image,Video,Audio messages
  • Typing Indicators.
  • Delivered and Read receipts.
  • Chat history
  • Chat user list
  • Contact details

Quickstart

To start with an existing app , just initialize the sdk in your Application’s onCreate() method and start using the SDK features

Please note that we are using Java 8 in our sdk, so you have to add Java 8 support in compile options

We are using AndroidX in our sdk, so please add AndroidX support in gradle.properties

Once you do these pre-requisites, you are ready to start using our sdk

API Documentation

To validate the namespace of your app

eRTCSDK.tenant().validate(namespace).subscribe(
    Consumer<Result> { this.success(it) }, error
)

How to login with username and password

login(AccountDetails details);


E.g. :-
eRTCSDK.tenant().login(AccountDetails.username(username, password)).subscribe(
   Consumer { this.success(it) }, error
)

Forgot Password:

Provide namespace to get the password in the mail:

eRTCSDK.tenant().forgotPassword(AccountDetails.forgotPwd(namespace)).subscribe(
   Consumer { this.success(it) }, error
)

Change Password

eRTCSDK.tenant().changePassword(AccountDetails.changePwd(oldPassword, newPassword)).subscribe(
   Consumer { this.success(it) }, error
)

To initiate chat , you have to create thread with the recepient:

eRTCSDK.chat().createThread("testthread", user.id)   //testhread is thread
name, you can choose to not provide

Code Example:

disposable.add(eRTCSDK.chat().createThread("", user.id).subscribe({
   //open chat screen to begin chatting
}, {
   //handle error
}))

To send a text message :

API signature : sendMessage(String text, String threadId);
String textMessage = “Hi!! What are you up to”;
eRTCSDK.chat().sendMessage(textMessage, threadID);

To send media message :

sendMedia(String mediaPath, String threadId, String mediaType)
//mediaType = ‘image’/’audio’/’video’
eRTCSDK.chat().sendMedia(
    filePath,                 //filePath
    threadID,
    messageRecord.msgType       //msgType = ’image’/’audio’/’video’
)

Code Example:

For capturing photos:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files"
path="." />
</paths>

And in AndroidManifest.xml , add this under application tag

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>

To get file for startTakePhotoAcitivty , use this

fun getPhotoImageFile(): File {
var cameraImage:File? = null
val mediaSelector = MediaSelector()
cameraImage = mediaSelector.getPictureFile()
return cameraImage;
}
fun capturePhoto(activity: Activity, cameraImage: File, requestCode: Int) {
Permissions.with(activity).request(Manifest.permission.CAMERA).ifNecessary()
.withPermanentDenialDialog(activity.getString(R.string.attachment_take_photos_denied)) .onAllGranted {
val mediaSelector = MediaSelector()
mediaSelector.startTakePhotoActivity(activity, cameraImage)
}.execute()
}

Choose Photos:

fun selectGallery(activity: Activity, requestCode: Int) {
Permissions.with(activity).request(Manifest.permission.WRITE_EXTERNAL_STORAGE).ifNecessary()
.withPermanentDenialDialog(activity.getString(R.string.attachment_photos_videos_or_audio_denied))
.onAllGranted {
val mediaSelector = MediaSelector()
mediaSelector.startChooseImageActivity(activity)
}.execute()
}

How to Add the eRTC Client SDK to your Android App

Gradle

To download the SDK, you will need to include the repository manually:

Add repository.

repositories {
   mavenCentral()
   maven { url "http://artifactory.pantepic.com/artifactory/ext-sdk-rel" }
}

Then add this to your dependencies area.

implementation 'com.ripbull.ertcsdk:coreSdk:1.0.0'

You also need to enable Java 8.

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Android X

Make sure you've added the following to your gradle.properties file.

android.useAndroidX=true

Initializing the Chat SDK

Now open your applications's main class and find the onCreate method. Add the following to setup the Chat SDK:

try {
   val config = Configuration.Builder()

   // SDK initialize
   eRTCSDK.initializeWithConfig(this, config.build());

} catch (ChatSDKException e) {
   // Handle any exceptions
   e.printStackTrace();
}

How to Send Chat Text Message

A chat between two users is considered as a thread of communication. To initiate chat between users, you need to create threads and send message over that thread ID.
To do that :

/*
Here user.id corresponds to the id of the user, you need to initiate chat with. Create Thread method takes two params, one is thread name and the second one is user id
*/

eRTCSDK.chat().createThread("", user.id);
//use the thread id created from above to start text messaging
String textMessage = “This is a text message”;
eRTCSDK.chat().sendMessage(textMessage, threadID);

How to create Threads for Chat?

/*
Here user.id corresponds to the id of the user , you need to initiate chat with. createThread method takes two params, one is thread name and the second one is user id
*/

eRTCSDK.chat().createThread("", user.id);

How to send Chat message?

Use the thread id created from above to start text messaging

String textMessage = “This is a text message”;
eRTCSDK.chat().sendMessage(textMessage, threadID);

How to handle permissions

How To use attachment library :

E.g. :

Take Photos :

fun capturePhoto(activity: Activity, requestCode: Int) {

Permissions.with(activity).request(Manifest.permission.CAMERA).ifNecessary()
   .withPermanentDenialDialog(“Denied Permission”)
   .onAllGranted {
      val mediaSelector = MediaSelector()
      mediaSelector.startTakePhotoActivity(activity, MediaSelector.Result {
      })

   }.execute()
}

How to send media message :

eRTCSDK.chat().sendMedia(
    Message,                   //filePath
    threadID,
    messageRecord.msgType       //msgType = ’image’/’audio’/’video’
)

How to Implementation of Notifications / FCM module:-

/*
You need FCM registration before Login API. for that you write below line in your application
*/

eRTCSDK.registerFCMToServer()

/*
For redirection to an acitivity , say MainActivity, You need to set Intent using below code
*/

val intent = Intent(applicationContext, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
Intent.FLAG_ACTIVITY_CLEAR_TOP
eRTCSDK.getIntentForFCM(intent)

/*
To manage thread based notification, When user clicked on Notification you need to write below piece of code(e.g. In MainActivity)
*/

override fun onNewIntent(intent: Intent?) {
   super.onNewIntent(intent)
   if (intent != null) {
      intent.hasExtra("threadId")
      eRTCSDK.removeNotification(intent)
   }
}

Resources

Modules:

  • Core SDK module
  • Permission module
  • Attachment module
  • Data Module
  • MQTT module
  • Analytics module
  • Core Http Module (Rest Apis)
  • Core Encryption