我是 Android 新手,我一直在尝试显示一个提醒操作推送通知,就像 Whatsapp 所做的那样。
这是我的通知配置:
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, ADMIN_CHANNEL)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_foreground))
.setSmallIcon(R.drawable.m_icon)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setTicker(remoteMessage.getNotification().getBody())
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.mblue))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(remoteMessage.getNotification().getBody()))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(likePendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
我在一些帖子中读到,实现这一点的关键是为通知设置高优先级,但是,它仍然对我不起作用。
对于模拟器上的 Android Pie (9),我将通道设置为“IMPORTANCE_HIGH”,并将构建器优先级设置为“PRIORITY_HIGH”。
但是,我仍然无法收到提醒通知!
最后,在 Android 9 模拟器上,我必须:
- 向下滑动通知抽屉
- 点击“管理通知”
- 选择我的应用程序
- 选择我的频道
- 选择“行为”
- 启用“发出声音并在屏幕上弹出”。
现在可以了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)