Php firebase推送通知自动清除以前的通知
我在android应用程序中使用FCM设置推送通知,我使用FCM数据而不是通知。我已经添加了唯一id来从我的服务器推送消息,但在我的应用程序中,当收到新通知时,它会自动清除我以前的通知。 my push.php代码Php firebase推送通知自动清除以前的通知,php,android,firebase,kotlin,push-notification,Php,Android,Firebase,Kotlin,Push Notification,我在android应用程序中使用FCM设置推送通知,我使用FCM数据而不是通知。我已经添加了唯一id来从我的服务器推送消息,但在我的应用程序中,当收到新通知时,它会自动清除我以前的通知。 my push.php代码 class Push { //notification title private $title; //notification message private $message; //notification image url private $image; privat
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!!)
}
}
通知助手
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服务中添加任何其他内容,以及如何在其中使用唯一id来不清除上一条消息。将此行中的1替换为唯一id。
mNotificationMgr.notify(1,mBuilder.build())将此行中的1替换为唯一ID。 mNotificationMgr.notify(1,mBuilder.build())