Skip to main content
Version: 5.1.0

Configuring Notifications

You need to configure notifications and add meta information about data store:

  1. Permissions:
<permission android:name="${applicationId}.permission.pushserver.RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="${applicationId}.permission.pushserver.RECEIVE" />
  1. Meta information:
<meta-data
android:name="im.threads.getServerUrl"
android:value="YOUR_DATASTORE_URL" />

YOUR_DATASTORE_URL parameter will be issued to you once you connect.

Additional Info

  • Enabling of debug logging of the push library:
<meta-data
android:name="com.pushserver.android.logs"
android:value="true"/>

Firebase

For push notifications to work correctly, you need to define the heir in the application https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService. To pass the token in the respective methods of the heir, use ChatCenterPushMessageHelper.setFcmToken(...). To process an incoming push notification, use ChatCenterPushMessageHelper.process(...). This method will only process the push notifications that contain origin=threads, i.e. the edna Chat Center membership flag.

Adding google-services.json

The following two options are possible:

  • Using your Firebase account, generate a google-services.json file. To get registered in the syste, specify your project_number and API_KEY from the Firebase console (not from google-services.json).
  • Using your Firebase account, specify yuor app's applicationId, and we'll send you the google-services.json file.

You need to add the google-services.json file to the project next to AndroidManifest.xml

Configuring Manifest

Registering a handler:

<service android:name=".push.CustomPushFcmIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

Push Notifications

When receiving information from Firebase, you need to save it to the library. You also need to register a handler for new messages. For that, you need to redefine the FirebaseMessagingService class:

class CustomPushFcmIntentService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
ChatCenterPushMessageHelper.setFcmToken(token)
}
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
ChatCenterPushMessageHelper.process(this, message.data)
}
}

Also, you need to pass the key from Firbase push notifications. You can do it via the manifest:

<meta-data
android:name="im.threads.threadsGateProviderUid"
android:value="YOUR_THREADS_GATE_FCM_PROVIDER_UID"/>

or by calling a respective method when creating Transport Config at the time of library connection:

class ThreadsDemoApplication : Application() {
override fun onCreate() {
super.onCreate()
val configBuilder = ConfigBuilder(this) // this - android context
val transportConfig = getTransportConfig(this)
configBuilder.threadsGateProviderUid(transportConfig.threadsGateProviderUid)

ThreadsLib.init(configBuilder)
}

fun getTransportConfig(ctx: Context?): TransportConfig? {
// ...
val threadsGateProviderUid =
sharedPreferences.getString(PREF_THREADS_GATE_PROVIDER_UID, null)
?: return null

return TransportConfig(
// ...
threadsGateProviderUid
)
}
}

Huawei Media Services (HMS)

Enabling Push Notifications

The configuration process is similar to the one for Firebase.

Add HMS to the project https://developer.huawei.com/consumer/en/codelab/HMSPushKit/index.html.

When you receive information from Huawei, you need to save it to the library. You also need to register a handler for new messages. For that, you need to redefine the HmsMessageService class:

class CustomPushHcmIntentService : HmsMessageService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
ChatCenterPushMessageHelper.setHcmToken(token)
}
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
ChatCenterPushMessageHelper.process(
this,
CommonUtils.base64JsonStringToBundle(message.data)
)
}
}

Then you need to add the handler to the manifest:

<service
android:name=".push.CustomPushHcmIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>

Integration with Push Lite

info

This section is only relevant for the projects that already use SDK push-lite to deliver push notifications. To configure and integrate push-lite, follow the instructions provided with the SDK.

After integration with the required push clients has been successfully completed, you can start integration with Chat Center. To do this, you need to add the following logic to transfer tokens and messages to the SDK:

  • For Firebase:
class CustomPushFcmIntentService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
ChatCenterPushMessageHelper.setFcmToken(token)
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
ChatCenterPushMessageHelper.process(this, message.data)
}
}
  • For HMS:
class CustomPushHcmIntentService : HmsMessageService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
ChatCenterPushMessageHelper.setHcmToken(token)
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
ChatCenterPushMessageHelper.process(
this,
CommonUtils.base64JsonStringToBundle(message.data)
)
}
}

After that, you need to add the declaration of both services to the manifest:

<service android:name=".push.CustomPushFcmIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<service
android:name=".push.CustomPushHcmIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
caution

Take note of adding the PushController.getInstance(this).init() method to Application.onCreate() that occurs in step 1.2.3 of the push-lite documentation.