Migration Guide Chat SDK Android Native from v1.x.x to v3.x.x (support Multiple App IDs)

  • Updated

Migration Guide

If you're migrating from an older version of the Chat SDK, this guide will help to highlight some of the key differences.

Prerequisites

Before

  • compileSdkVersion 29
  • targetSdkVersion 29
  • [JDK 1.8]
  • [Android Studio 3]

After

  • compileSdkVersion 33
  • targetSdkVersion 33
  • [JDK 11]
  • [Android Studio 4]

Initializing the Chat SDK

The Chat SDK initialization should take place in your Application.java. The initialization method takes the following parameters:

  • QISCUS_SDK_APP_ID : This can be found on the Chat dashboard. Ask a Chat admin for the key if you don't have access to the dashboard.
  • Context : Android Context object, typically obtained from your application's Application class or an Activity. It provides essential information about the application's environment and is used for various Android system interactions.

Before

QiscusCore.setup(this, BuildConfig.QISCUS_SDK_APP_ID);

 

After

In the newer version of the Qiscus Chat SDK (v3.x.x), you can initialize the SDK with multiple App IDs by creating separate QiscusCore objects for each App ID. This allows you to manage different chat configurations and endpoints for different applications within your Android project.

1. Declare QiscusCore Objects

In your Android application, declare separate QiscusCore objects for each App ID that you want to use. You can create these objects as class members or variables within your code.

private QiscusCore qiscusCore1;
private QiscusCore qiscusCore2;

2. Create Const class

create a Const class to encapsulate the QiscusCore instances and provide a convenient way to access them

import com.qiscus.sdk.chat.core.QiscusCore;

public class Const {

private static QiscusCore qiscusCore1;
private static QiscusCore qiscusCore2;

public static void setQiscusCore1(QiscusCore qiscusCore1) {
Const.qiscusCore1 = qiscusCore1;
}

public static void setQiscusCore2(QiscusCore qiscusCore2) {
Const.qiscusCore2 = qiscusCore2;
}

public static QiscusCore getQiscusCore1() {
if (qiscusCore1 != null) {
return qiscusCore1;
} else {
throw new IllegalStateException("QiscusCore 1 is null");
}
}

public static QiscusCore getQiscusCore2() {
if (qiscusCore2 != null) {
return qiscusCore2;
} else {
throw new IllegalStateException("QiscusCore 2 is null");
}
}
}


3. Initialize QiscusCore Objects

Create new instances of QiscusCore for each App ID you want to use. You can do this in your application's initialization code, such as in the onCreate() method of your Application class.

// Initialize QiscusCore instances
qiscusCore1 = new QiscusCore();
qiscusCore12 = new QiscusCore();
qiscusCore1.setup(this, QISCUS_SDK_APP_ID1);
qiscusCore2.setup(this, QISCUS_SDK_APP_ID2);
// Set the QiscusCore instances in the Const class
Const.setQiscusCore1(qiscusCoreInstance1);
Const.setQiscusCore2(qiscusCoreInstance2);

3. Usage with Specific QiscusCore Object

When working with chat functionality for a specific App ID, use the corresponding QiscusCore object that you've initialized.

// Example usage with the first QiscusCore object (App ID 1)
Const.qiscusCore1().getApi()
.chatUser(.....) // Example usage with the second QiscusCore object (App ID 2) Const.qiscusCore2().getApi()
.chatUser(.....)

Notes

  • In the newer version of the Qiscus Chat SDK, you need to create separate QiscusCore instances for each App ID you intend to use within your Android application.

  • Initializing each QiscusCore object with its respective App ID ensures that chat functionality is correctly configured for each application, and messages are sent and received using the appropriate chat configuration.

  • Replace "QISCUS_SDK_APP_ID1" and "QISCUS_SDK_APP_ID2" with your actual Qiscus Chat SDK App IDs.

Calling QiscusApi instance

In version V3.x.x of the Chat SDK, there has been a change in the way you call the Qiscus API. This change aims to improve code organization and maintainability by introducing a more consistent and centralized approach for API access.

Previous Approach

In previous versions of the Chat SDK, you would typically call the Qiscus API using the QiscusApi.getInstance() method, like this:

QiscusApi.getInstance().yourApiMethodHere(...);

New Approach

Starting from version v3.x.x , you should use the Const.qiscusCore().getApi() method to access the Qiscus API. This approach offers greater flexibility and consistency in managing your API calls. Here's how you can use it:

Const.qiscusCore().getApi().yourApiMethodHere(...);

Calling QiscusCacheManager instance

In version V3.x.x of the Chat SDK, there has been a change in the way you call the QiscusCacheManager. This change aims to improve code organization and maintainability by introducing a more consistent and centralized approach for API access.

Previous Approach

In previous versions of the Chat SDK, you would typically call the Qiscus API using the QiscusCacheManager.getInstance(). method, like this:

QiscusCacheManager.getInstance().yourApiMethodHere(...);

New Approach

Starting from version v3.x.x , you should use the Const.qiscusCore().getCacheManager() method to access the QiscusCacheManager. This approach offers greater flexibility and consistency in managing your API calls. Here's how you can use it:

Const.qiscusCore().getCacheManager().yourApiMethodHere(...);

Handling Incoming Messages from Push Notifications

in version v3.x.x of the Chat SDK, there has been a change in how you handle incoming messages from push notifications. This change aims to enhance the organization and customization of push notification handling, especially when managing multiple App IDs within your application.

Previous Approach

In older versions of the Chat SDK, you would typically handle incoming messages from push notifications using the QiscusFirebaseMessagingUtil.handleMessageReceived(remoteMessage) method:

QiscusFirebaseMessagingUtil.handleMessageReceived(remoteMessage);

New Approach

Starting from version v3.x.x, the handling of incoming messages from push notifications is tied to specific QiscusCore instances for each App ID. You should use the following approach to handle push notifications for each App ID:

// Handling push notifications for App ID 1 
Const.qiscusCore1().getFirebaseMessagingUtil().handleMessageReceived(remoteMessage);
// Handling push notifications for App ID 2
Const.qiscusCore2().getFirebaseMessagingUtil().handleMessageReceived(remoteMessage);

You can find a real-world example of this approach in the AppFirebaseMessagingService.java file within the Chat SDK Android Sample on GitHub.

Determining the Type of a Chat Room

In version v3.x.x of the Chat SDK, there has been a change in how you determine the type of a chat room. This change aims to provide a more standardized and explicit approach to identifying chat room types.

Previous Approach

In older versions of the Chat SDK, you would typically use the chatRoom.isGroup() method to check if a chat room is a group chat:

New Approach

Starting from version v3.x.x, the recommended approach is to use the chatRoom.getType() method and compare it to the desired type, such as "group", to determine the chat room type:

boolean isGroupChat = "group".equals(chatRoom.getType());

Renamed Classes, Function, and Models

In version v3.x.x of the Chat SDK, several classes, functions, and models have been renamed to improve clarity, consistency, and alignment with best practices. These changes aim to enhance the overall development experience and maintain compatibility with the evolving standards of the SDK.

This section provides an overview of the renamed components and their new names. Developers should review these changes to ensure a smooth transition when upgrading to this version.

List of Renamed Model

  • QiscusChatRoom is renamed to QChatRoom.
  • QiscusAccount is renamed to QAccount.
  • QiscusRoomMember is renamed to QParticipant.
  • QiscusComment is renamed to QMessage.
  • QiscusCommentReceivedEvent is renamed to QMessageReceivedEvent

List of Renamed Function

  • getLastComment is renamed to getLastMessage in QChatRoom (previous QiscusChatRoom)
  • getMember is renamed to getParticipants in QChatRoom (previous QiscusChatRoom)
  • setMember is renamed to setParticipants in QChatRoom (previous QiscusChatRoom)
  • getEmail is renamed to getId in QParticipant (previous QiscusRoomMember)
  • setEmail is renamed to setId in QParticipant (previous QiscusRoomMember)
  • getUsername is renamed to getName in QParticipant (previous QiscusRoomMember)
  • getAvatar is renamed to getAvatarUrl in QAccount (previous QiscusAccount)
  • getTime is renamed to getTimestamp in QMessage (previous QiscusComment)
  • getCommentBeforeId is renamed to getPreviousMessageId in QMessage (previous QiscusComment)
  • getMessage is renamed to getText in QMessage (previous QiscusComment)
  • getRoomId is renamed to getChatRoomId in QMessage (previous QiscusComment)

Important Notes

  1. Ensure whether multiple APP IDs are used within one app.
  2. If multiple APP IDs are used within one app, you can use QiscusCore v.3.0.0-beta.27. Sample SDK for multiple APP IDs: link Sample Omnichannel Widget: link
  3. If different APP IDs are used within one app, meaning that the SDK app and Omnichannel are separate apps, you can use QiscusCore latest v.1.6.10. Sample SDK for a single APP ID: link Sample Omnichannel Widget: link
  4. See this comparison between older version to v3.x.x and and MIGRATION-GUIDE on github for further information
  5. for further information

Related to

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.