Skip the create new app step. Your existing v2 app can be migrated to v3. > > Follow steps mentioned in Add the CometChat dependency section below to upgrade to latest version of v3
Get your Application Keys
Signup for CometChat and then:- Create a new app
- Head over to the API Keys section and note the Auth Key, App ID & Region
Minimum Requirement
- Android API Level 21
- Android API level 24 (in case you are using the calls SDKS)
- Androidx Compatibility
Add the CometChat Dependency
Gradle
First, add the repository URL to the project levelbuild.gradle
file in the repositories
block under the allprojects
section:
build.gradle
file in the dependencies
section.
In case you plan to use the calling feature, please add the Calling dependency
implementation 'com.cometchat:calls-sdk-android:4.1.0'
in the dependencies section of the app-level build.gradle
file.android
section of the app level gradle file.
Initialize CometChat
Theinit()
method initialises the settings required for CometChat. The init()
method takes the below parameters:
- appID - You CometChat App ID
- appSettings - An object of the AppSettings class can be created using the AppSettingsBuilder class. The region field is mandatory and can be set using the
setRegion()
method.
AppSettings
class allows you to configure three settings:
- Region: The region where you app was created.
- Presence Subscription : Represents the subscription type for user presence (real-time online/offline status)
- autoEstablishSocketConnection(boolean value): This property takes a boolean value which when set to true informs the SDK to manage the web-socket connection internally. If set to false, it informs the SDK that the web-socket connection will be managed manually. The default value for this parameter is true. For more information on this, please check the Managing Web-Socket connections manually section. The default value for this property is true.
- overrideAdminHost(adminHost: string): This method takes the admin URL as input and uses this admin URL instead of the default admin URL. This can be used in case of dedicated deployment of CometChat.
- overrideClientHost(clientHost: string): This method takes the client URL as input and uses this client URL instead of the default client URL. This can be used in case of dedicated deployment of CometChat.
init()
method on app startup.
Parameter | Description |
---|---|
this | Android context for your application |
appID | CometChat App ID |
appSetting | An object of the AppSettings class. |
Auto Mode Connection
Know more about auto mode connection click here
App State | Behaviour |
---|---|
App in foreground | Connected with WebSocket |
App in background | Immediately disconnected with WebSocket |
Manual Mode Connection
Know more about manual mode connection click here
App State | Behaviour |
---|---|
App in foreground | Call CometChat.connect() to create the WebSocket connection |
App in background | Disconnect the WebSocket connection if no ping is received within 30 seconds after the app goes in the background. |