Android SDK

Overview

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

The following principles are followed during development

  • Modularity: Code is segregated into multiple modules and follows 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'll need to add Java 8 support in the compile options
  • We are using AndroidX in our SDK, so please add AndroidX support in gradle.properties
  • Once you do these prerequisites, 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 log in with username and password

login(AccountDetails details);


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

Forgot Password:

Provide namespace to get the password in your email:

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

Change Password:

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

To Initiate Chat, You Have to Create a 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:

Create a file_paths.xml file in res>xml folder, and add the content :-

<?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()
}

To Load User List:

getUsersInSync(tenantId: String, lastId: String?)

E.g : Code below:

eRTCSDK.user().users
   .subscribeOn(Schedulers.io())
   .observeOn(AndroidSchedulers.mainThread())
   .subscribe(
      this::onUserListSuccess,      //handle user list success
      this::onUserListError         //handle user list failure
   )
private fun onUserListSuccess(userList: List<UserRecord>) {
}

private fun onUserListError(throwable: Throwable) {
}

How to Add the eRTC Client SDK to Your Android App

Integration with an existing project is simple. You can add the core libraries using Gradle.

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-rbn" }
    }
  • Then add this to your dependencies area.
    implementation 'com.ripbull.ertcsdk:coreSdk:1.0.0'
       transitive = true
    }
  • 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 application's main class and find the onCreate method. Add the following to setup the Chat SDK:

try {
// set your api key here
val config =
Configuration.Builder().context(this).apiKey("edu6qgwsjxxxxxApiKey").build()

// SDK initialize
   eRTCSDK.initializeWithConfig(config)


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

Sending a 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:

Creating 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 above to start text messaging

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

How to Block/Unblock a User

To block a user: action = “block”

To unblock a user: action = “unblock”

eRTCSDK.chat().blockUnblock(action, user!!.id).subscribeOn(Schedulers.io()).observeOn(
   AndroidSchedulers.mainThread()
).subscribe({
   //user is blocked/unblocked depending upon the action passed

}, { it.printStackTrace() })

Viewing Blocked Users

eRTCSDK.chat().blockedUsers().subscribeOn(Schedulers.io()).observeOn(
   AndroidSchedulers.mainThread()
).subscribe({
   //check user.isBlocked to see if a particular user is blocked post this api call
}, { it.printStackTrace() })

How to Handle Permissions

Using the Attachment Library:

Sending a Media Message:

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

How to send document:

disposable.add(
  eRTCSDK.chat().sendDocument(
     threadID, message,
     messageRecord.msgType
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
   .subscribe({
   }, { it.printStackTrace() })
)

How to send contact:

disposable.add(
  eRTCSDK.chat().sendContact(
    threadID,
    messageRecord.contactName,
    messageRecord.phoneContactRecord,
    messageRecord.emailContactRecord
  ).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
    .subscribe({
    }, { it.printStackTrace() }))

How to send location:

disposable.add(
  eRTCSDK.chat().sendLocation(    threadID,
    messageRecord.locationRecord?.address,
    messageRecord.locationRecord?.latitude!!,
    messageRecord.locationRecord?.longitude!!
  ).subscribeOn(Schedulers.io()).observeOn(
    AndroidSchedulers.mainThread()
  ).subscribe({
  }, { it.printStackTrace() })
)

How to send GIF:

disposable.add(eRTCSDK.chat().sendGIF(
  threadID, message
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe({
  }, { it.printStackTrace() })
)

How to set message as favourite (markAsFavorite):

eRTCSDK.chat().markAsFavorite(
  threadID, msgSelectedList, isFavorite) // isFavourite = true/false*
  .subscribe({
  }, { it1 -> it1.printStackTrace() })
Info*: if isFavorite = true means set as Favorite else remove from Favorite

Mark message as read (for particular thread):

disposable.add(
  eRTCSDK.typing().subscribe(threadID).observeOn(AndroidSchedulers.mainThread()).subscribe({
    typing: TypingIndicatorRecord ->
    // set typing indicator for period of time
    setSubTitleText(it)      // set sub title of action bar to (typing...)
  }, { it.printStackTrace() })
)

Mark message as read (for particular thread):

eRTCSDK.chat().markRead(threadId)

Get Message list to initialize the Recycler view:

// to get list of messages
disposable.add(
  eRTCSDK.chat().getMessages(threadID).subscribeOn(Schedulers.io()).observeOn(
    AndroidSchedulers.mainThread()
  ).subscribe({
    messageList -> // initialize the Recycler view (messageList: List)
  },{
    it.printStackTrace()
  }
))

// Mqtt network event
disposable.add(
  eRTCSDK.chat().messageOn().subscribe({

  }, { it.printStackTrace() })
)

Get Thread history (users and groups) :

List of users and groups whom you have did chat conversation

getOnStartDisposable()?.add(
  eRTCSDK.chat().threads.subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread()).subscribe({
      list: List<ThreadRecord> ->
    // set recycler view to display list of thread list
  },{it.printStackTrace()})
)

User module: Update user profile

disposable.add(
  eRTCSDK.user().updateProfile(
    etStatus.text.toString(), this.filePath.let { if(it.isNullOrEmpty()) "" else it },
    AttachmentManager.MediaType.IMAGE.toString()
  )
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({
      finish()
    }, {
      it.printStackTrace()
    })
)

User module: Remove user profile picture

disposable.add(
  eRTCSDK.user().removeProfilePic()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({
      finish()
    }, {
      it.printStackTrace()
    })
)

User module: How to logout from application

disposable.add(
  eRTCSDK.user().logout().subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({
      activity!!.finish()
    }, { it.printStackTrace() })
)

User module: How to set user availability

val status = AvailabilityStatus.AUTO or AvailabilityStatus.AWAY or AvailabilityStatus.INVISIBLE or
AvailabilityStatus.DND

disposable.add(eRTCSDK.user().setUserAvailability(status)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({
      //set here what you choose
    }, {
      it.printStackTrace()
}))

Group module: How to create private group

disposable.add(eRTCSDK.group().createPrivateGroup(groupRecord)
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread()).subscribe({
    groupRecord ->
  },{ it.printStackTrace() }
))

Group module: How to get list of groups

getOnStartDisposable()?.add(
  eRTCSDK.group().groups.subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread()).subscribe({
      list: List ->
      // set recycler view to display list of groups
    },{it.printStackTrace()})
)

Group module: How to update group detail

getOnStartDisposable()?.add(eRTCSDK.group().updateGroupDetail(
  groupDetail?.groupId,      // groupId
  edt_group_name.text.toString(),      // group name
  edt_group_desc.text.toString(),      // group description
  this.filePath.let { if(it.isNullOrEmpty()) "" else it } // group picture path
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe({
    groupRecord ->
  },{it.printStackTrace()}
))

Group module: How to add participants in the group

disposable.add(
  eRTCSDK.group().addParticipants(groupId, userList).subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread()).subscribe({
      // Participants added successfully
    },{
      it.printStackTrace()
    })
)

Group module: How to remove participants from the group

disposable.add(
  eRTCSDK.group().removeParticipants(group.groupId, userList).subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread()).subscribe({
      groupRecord ->
    },{
      it.printStackTrace()
    }
))

Group module: How to make Admin

disposable.add(
  eRTCSDK.group().addAdmin(groupId, userRecord.id).subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread()).subscribe({
      groupRecord ->
    },{
      it.printStackTrace()
    }
))

Group module: How to dismiss as Admin

disposable.add(
  eRTCSDK.group().removeAdmin(groupId, userRecord.id).subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread()).subscribe({
      groupRecord ->
    },{
      it.printStackTrace()
    }
))

Group module: How exit from the group

disposable.add(
  eRTCSDK.group().exitGroup(groupId).subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread()).subscribe({
      // Successfully removed from the group
        finish()
    },{
      it.printStackTrace()
    }
))

Group module: How to remove group profile picture:

disposable.add(
  eRTCSDK.group().removeGroupPic(groupDetail?.groupId)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({
      // Success (remove profile picture from imageView)
      ivUserProfile.setImageResource(R.drawable.ic_group)
    }, { it.printStackTrace() })
)

Implementing 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 activity, such as MainActivity, you need to set Intent using the code below.
*/

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, please add the code below.
*/

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
Resource Image