Я работаю над приложением, основанным на Push-уведомлениях (Custom Notifications). Я использую FCM
и javascript (index.js)
. Я могу запустить push-уведомление отлично, но проблема в звуке. Я хочу Push-уведомление со звуком в одном состоянии (if
) и без звука в другом (else
). Что происходит, в обоих условиях я получаю звук. Как я могу вызвать push-уведомление без звука?
String remoteMessageSound = remoteMessageData.get(REMOTE_SOUND);
if (remoteMessageSound.equals("default")) {
Notification notificationDefault = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id))
.setSmallIcon(R.drawable.namma_apartment_notification)
.setAutoCancel(true)
.setContentTitle(getString(R.string.app_name))
.setContentText(message)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setPriority(PRIORITY_DEFAULT)
.build();
Objects.requireNonNull(notificationManager).notify(mNotificationID, notificationDefault);
} else {
Notification notificationNoSound = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id))
.setSmallIcon(R.drawable.namma_apartment_notification)
.setAutoCancel(true)
.setContentTitle(getString(R.string.app_name))
.setContentText(message)
.setSound(null)
.setPriority(PRIORITY_LOW)
.build();
Objects.requireNonNull(notificationManager).notify(mNotificationID, notificationNoSound);
}
А это мой index.js:
if (cabNotificationSound) {
payload = {
data: {
message: "Your Cab has " + status + " your society.",
"sound": "default",
type: "Cab_Notification"
}
};
}
else {
payload = {
data: {
message: "Your Cab has " + status + " your society.",
"sound": "",
type: "Cab_Notification"
}
};
}
return admin.messaging().sendToDevice(tokenId, payload).then(result => {
return console.log("Notification sent");
});