android - 在android中显示数字而不是消息的前台通知
问题描述
我正在从Firebase 控制台测试推送通知
当我的应用程序处于后台时,我成功收到了通知
但是在前台,无论我发送的通知消息显示给我什么消息都是这样的:
我不知道这个数字是从哪里来的。
下面是我创建通知的代码:
override fun onMessageReceived(p0: RemoteMessage) {
super.onMessageReceived(p0)
p0.notification?.let {
val notif = NotificationCompat.Builder(this, "12345")
.setContentTitle(p0.from)
.setContentText(p0.to)
.setSmallIcon(R.drawable.ic_menu_send)
.build()
val manager = NotificationManagerCompat.from(applicationContext)
.notify(0, notif)
}
}
以下是Firebase 控制台的屏幕截图:
有人可以告诉我如何正确接收我的消息。
更新:还有为什么后台和前台通知 的这种差异
提前致谢。
解决方案
您正在发送通知消息。您可以按以下方式获取标题和正文
override fun onMessageReceived(p0: RemoteMessage) {
super.onMessageReceived(p0)
val title = message.notification.title
val body= message.notification.body
p0.notification?.let {
val notif = NotificationCompat.Builder(this, "12345")
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.ic_menu_send)
.build()
val manager = NotificationManagerCompat.from(applicationContext)
.notify(0, notif)
}
你可以在这里获得更多信息
推荐阅读
- php - 选择等于现在的日期时间字段
- angular - 使用 ASP.NET Core 在 Angular 项目模板中将开发环境设置为本地生产
- r - 部分基于全局变量返回数据集的函数
- android - Cannot resolve symbol - Bitmap image compress and upload to Firebase
- google-cloud-platform - 在 Google Cloud Console 免费试用到期时恢复 VM 实例
- google-app-engine - 从 gloud app deploy 上传的文件在哪里?
- r - Getting subscripts from Excel into R
- angular - Angular CanActivate 无法按预期工作
- jquery - Jquery Datepicker 日停用
- javascript - ES6 从对象中获取随机元素,不重复