Skip to main content

Notifications

You can enable notifications in DiyalogSDK. It uses Firebase services for app that deployed to Google App store and Huawei Mobile Services for app that deployed Huawei App Gallery.

Firebase Cloud Messaging integration#

In Diyalog SDK we have used firebase messaging platform for sending push notification. so we have used firebase services in sdk. Client need to configure as below into main application.

For application that deployed to Google App Store :

implementation "im.diyalog:DiyalogGoogleExtension:version-no"

*version-no should be the current stable version of Diyalog Android SDK.

To create a Firebase project#

Need to do configure below Steps on firebase console

Step 1: Create a Firebase project in the Firebase console, if you don't have any project then Click Add project. If you already have an existing Google project associated with your mobile app, select it from the Project name drop down menu. Otherwise, enter a project name to create a new project

Step 2: Follow the remaining steps and click Create project (or Add Firebase if you have existing project) for your project. When the process completes, you'll be taken to the project overview.

Now that you have a project, you can add your Android app to it#

Step 1: Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.

Step 2: When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.

Step 3: During the process, you'll download a google-services.json file. You can download this file again at any time.

Step 4: After you add the initialization code, run your app to send verification to the Firebase console that you've successfully installed Firebase.

Configuration Steps for android project#

Client need to perform a few basic steps to prepare your Android Studio project.

Step 1: Add google-services.json file to application level project. (usually the app/google-services.json)

Step 2: Add rules to your root-level build.gradle file, to include the google-services plugin and the Google's Maven repository.

buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
}
}
allprojects {
// ...
repositories {
// ...
google() // Google's Maven repository
}
}

Step 3: Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin. You should also add the dependencies for the Firebase SDKs.

apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
implementation 'com.google.firebase:firebase-messaging:17.6.0'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

Step 4: Now, client require to Pass sender ID/project ID to sdk from main application as below. client need to pass this pushID before Initialize() sdk. Client can register pushID into application class.

DiyalogEngine.diyalogInstance().setPushId(1234567890L);

Done. Above steps are enough for generating push notification, if main application has no any FCM integration. If you are usinf fcm in your app, you should follow next section to integrate to DiyalogSDK.

Main application has firebase push notification#

If in main application has also firebase push notification then client need to follow additinal below steps to configure FCM push notification.

Step 1: Client need send device token to diyalog sdk from main application's FirebaseMessagingService class.

public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.d(TAG, "New Token loaded: " + s);
DiyalogEngine.diyalogInstance().storeDeviceToken(getApplicationContext(),s);
}
}

Step 2: Client need to pass push payload data(RemoteMessage) to diyalog sdk from application's FirebaseMessagingService.

public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
/**
* Diyalog sdk has "seq" in push payload,
* So with this key client can bifurcate push payload.
*/
String seq_ID = remoteMessage.getData().get("seq");
String callId = remoteMessage.getData().get("callId");
if(seq_ID != null || callId != null) {
// push received for diyalog sdk
DiyalogInternalMessageService messageService = new DiyalogInternalMessageService(getApplication());
messageService.processPushMessage(remoteMessage.getData());
}else{
// push received for Main application
}
}
}

Step 3: Open your project AndroidManifest.xml file and register firebase service as below line of code inside application tag.

<!--FCM push notification-->
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

Huawei Mobile Services pushkit integration#

In Diyalog SDK we have used Huawei Mobile Services platform for sending push notification to Huawei devices that installs application from App Gallery. Client need to configure as below into main application.

For application that deployed to Huawei App Gallery :

implementation "im.diyalog:DiyalogHuaweiExtension:version-no"

*version-no should be the current stable version of Diyalog Android SDK.

To create a Huawei Mobile Services PushKit project#

Need to do configure below Steps on HSM console

Step 1: Create an account and your project in Huawei Mobile Services platform.

Step 2: Create your project in AppGallery connect. Enable pushkit api for your project.

Step 3: During the process, you'll download a agconnect-services.json file. You can download this file again at any time.

Configuration Steps for android project#

Client need to perform a few basic steps to prepare your Android Studio project.

Step 1: Add agconnect-services.json file to application level project. (usually the app/agconnect-services.json)

Step 2: Add rules to your root-level build.gradle file, to include the huawei-services plugin from Huawei maven repository.

buildscript {
// ...
dependencies {
// ...
classpath 'com.huawei.agconnect:agcp:1.2.1.301' // huawei-services plugin
}
}
allprojects {
// ...
repositories {
// ...
maven { url 'https://developer.huawei.com/repo/' }
}
}

Step 3: Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin. You should also add the dependencies for the Huawei SDKs.

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
android {
// ...
}
dependencies {
// ...
// push kit
implementation 'com.huawei.hms:push:4.0.3.301'
}

Step 4: Now, client require to Pass sender ID/project ID to sdk from main application as below. client need to pass this pushID before Initialize() sdk. Client can register pushID into application class.

DiyalogEngine.diyalogInstance().setPushId(1234567890L);

Done. Above steps are enough for generating push notification, if main application has no any FCM integration. If you are using HMS in your app, you should follow next section to integrate to DiyalogSDK.

Main application has Huawei Mobile Services pushkit#

If in main application has also HMS push notification then client need to follow additinal below steps to configure HSM pushkit.

Step 1: Client need send device token to diyalog sdk from main application's HmsMessageService class.

public class MyHuaweiHMSMessagingService extends HmsMessageService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
DiyalogEngine.diyalogInstance().storeDeviceToken(getApplicationContext(),s);
}
}

Step 2: Client need to pass push payload data(RemoteMessage) to diyalog sdk from application's HmsMessageService.

public class MyHuaweiHMSMessagingService extends HmsMessageService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
/**
* Diyalog sdk has "seq" in push payload,
* So with this key client can bifurcate push payload.
*/
String seq_ID = remoteMessage.getDataOfMap().get("seq");
String callId = remoteMessage.getDataOfMap().get("callId");
if(seq_ID != null || callId != null) {
// push received for diyalog sdk
DiyalogInternalMessageService messageService = new DiyalogInternalMessageService(getApplication());
messageService.processPushMessage(remoteMessage.getDataOfMap());
}else{
// push received for Main application
}
}
}

Step 3: Open your project AndroidManifest.xml file and register firebase service as below line of code inside application tag.

<!--HMS push notification-->
<service android:name=".push.MyHuaweiHMSMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>

Done :)

Custom notification sound#

The full host integration guide, with numbered steps, is on its own page: Custom Notification Sound.

The Diyalog Android SDK lets your app provide its own sound for SDK message notifications. When configured, this sound is used for:

  • System message notifications (app in background or killed)
  • In-app message sounds (app in foreground)
  • Inactive-user notifications

If you do not configure a sound, nothing changes: the SDK keeps using its existing notification channel and the system default sound. The call ringtone is not affected.

Prerequisites#

  • Diyalog Android SDK with host notification-sound support
  • A short audio file suitable for notifications (recommended: .ogg, .wav or .mp3)
  • The file placed under your app module's res/raw/ folder (example: res/raw/my_notification_sound.ogg)

Notification sound API#

Recommended: raw resource#

Use this when the sound ships inside your APK / AAB.

DiyalogEngine.diyalogInstance()
.setNotificationSound(R.raw.my_notification_sound);

Restore the default sound by passing 0: setNotificationSound(0).

Alternative: Uri#

Use a content:// or android.resource:// Uri when the sound is provided dynamically.

Uri soundUri = Uri.parse(
"android.resource://" + getPackageName() + "/" + R.raw.my_notification_sound);
DiyalogEngine.diyalogInstance().setNotificationSoundUri(soundUri);

Restore the default sound by passing null: setNotificationSoundUri(null).

ConstraintDetail
file:// URIsNot supported (Android 7+). Ignored; the SDK falls back to the default sound.
content:// URIsMust be readable by the system UI. If you use a FileProvider, grant read access to com.android.systemui.
TimingMust be called before Initialize() / createDiyalog().

Integration steps#

  1. Add your sound file to the app: app/src/main/res/raw/my_notification_sound.ogg (or .wav / .mp3).
  2. In Application.onCreate() (or your existing Diyalog setup), configure the engine before initialization.
  3. Call setNotificationSound(...) or setNotificationSoundUri(...).
  4. Then call Initialize() / createDiyalog() as you already do.
  5. Build, install, and verify with a real incoming message while the app is in the background.
@Override
public void onCreate() {
super.onCreate();
DiyalogEngine engine = DiyalogEngine.diyalogInstance();
// ... your existing host configuration ...
// MUST be before Initialize() / createDiyalog()
engine.setNotificationSound(R.raw.my_notification_sound);
// Existing initialization
engine.createDiyalog(this);
}

Android 8+ (Oreo) channel behavior#

Android does not allow changing a notification channel's sound after the channel is created. Therefore:

  • When a host sound is set, the SDK uses a dedicated channel: im.diyalog.diyalogapp.sound.<hash>
  • The previous SDK message channel is removed so the new sound can take effect
  • Any user-customized settings on the old channel are reset
  • If you configure nothing, the existing im.diyalog.diyalogapp channel and default sound stay unchanged

Verification checklist#

  • The sound resource exists under res/raw and compiles as R.raw.*
  • setNotificationSound / setNotificationSoundUri is called before Initialize()
  • Notification permission is granted (Android 13+)
  • Device volume / Do Not Disturb allows notification sounds
  • A message received with the app in the background plays the custom sound
  • Optional: a message received in the foreground plays the same sound in-app
  • The call ringtone is unchanged

Troubleshooting#

SymptomLikely cause / action
Still hearing the default soundThe call was made after Initialize(), or setNotificationSound(0) / null was used. Move the call before initialization and reinstall / reopen the app.
No sound at allCheck notification permission, channel importance, and that the messenger notification sound is enabled in SDK settings.
Uri sound ignoredfile:// is rejected. Use android.resource:// or a readable content:// Uri.
Sound change not applied on Android 8+Expected: a channel's sound cannot change. The SDK creates a new channel for the new sound; trigger a fresh notification after the change.

For support, contact your Diyalog integration representative and include the SDK version, the device OS version, and whether the call was made before Initialize().