【发布时间】:2020-11-19 10:23:36
【问题描述】:
我将这个答案用于前台和后台以接收 firebase 通知 --> https://stackoverflow.com/a/38451582/12553303
实际上以下是我的疑问:---------
如果我没有为前台条件编写代码(谈论推送通知)我仍然会在我的应用程序处于后台时收到通知吗???-->是的
但是当我处于前台状态并且我从 firebase 推送通知时-->我不会在状态栏上看到通知也可以(因为假设我没有覆盖 onmessagereceive() 方法)....然后接下来我去背景状态我没有看到任何我发送的背景通知
我应该怎么做才能获得我发送给后台的通知,比如从前台状态(没有 onmessagereceived 的方法())到 背景状态??*
感谢需要对此的建议和澄清...
这甚至可能让通知从前台状态移动到 背景状态??
代码:----
override fun onMessageReceived(p0: RemoteMessage) {
super.onMessageReceived(p0)
Log.d("msg", "onMessageReceived: " + p0.getData().get("message"))
val intent = Intent(this, OrderListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)
val channelId = "Default"
val builder: NotificationCompat.Builder =NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(p0.getNotification()?.getTitle())
.setContentText(p0.getNotification()?.getBody()).setAutoCancel(true)
.setContentIntent(pendingIntent)
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(channelId,
"Default channel",
NotificationManager.IMPORTANCE_DEFAULT)
manager.createNotificationChannel(channel)
}
manager.notify(0, builder.build())
}
任何建议将不胜感激,谢谢
【问题讨论】:
标签: android firebase kotlin push-notification firebase-cloud-messaging