Я использовал FCM для установки уведомления pu sh в своем приложении android, и я использую данные FCM, а не уведомление. я добавил уникальный идентификатор в сообщение pu sh с моего сервера, но в моем приложении при получении нового уведомления автоматически удаляются мои предыдущие уведомления. my pu sh. php код
class Push {
//notification title
private $title;
//notification message
private $message;
//notification image url
private $image;
private $notId;
//initializing values in this constructor
function __construct($title, $message, $image,$notId,$sound) {
$this->title = $title;
$this->message = $message;
$this->image = $image;
$this->notId = $notId;
$this->sound = $sound;
}
//getting the push notification
public function getPush() {
$res = array();
$res['title'] = $this->title;
$res['body'] = $this->message;
$res['image'] = $this->image;
$res['notId'] = $this->notId;
$res['sound'] = $this->sound;
return $res;
}
служба сообщений Firebase в моем приложении
lass myfirebasemessaging : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
super.onMessageReceived(remoteMessage)
if (remoteMessage!!.data != null) {
val title = remoteMessage.data!!.get("title")
val body = remoteMessage.data!!.get("body")
val tag = remoteMessage.data!!.get("notId")
NotificationHelper.displayNotification(applicationContext, title!!, body!!, tag!!)
}
}
NotificationHelper
fun displayNotification(context: Context, title: String, body: String, notId: String) {
val intent = Intent(context, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(
context,
100,
intent,
PendingIntent.FLAG_CANCEL_CURRENT
)
val mBuilder = NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
.setSmallIcon(R.drawable.ic_waterlogo)
.setContentTitle(title)
.setContentText(body)
.setStyle(NotificationCompat.BigTextStyle()
.bigText(body))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE)
val mNotificationMgr = NotificationManagerCompat.from(context)
val mp: MediaPlayer = MediaPlayer.create(context, R.raw.notification)
mp.start()
mNotificationMgr.notify(1, mBuilder.build())
}
так же, как я не мог сделать стиль для моего уведомления. Нужно ли мне добавить что-нибудь дополнительное в мой сервис fcm и как я могу использовать в нем уникальный идентификатор, чтобы не очистить предыдущее сообщение.