android - 如何在屏幕上显示通知。(火力基地)
问题描述
我的应用程序正在使用 firebase 推送通知,通知工作正常。我想做的是像 snapchat 和许多应用程序那样在屏幕上显示通知,但我不知道该怎么做:/
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
public void showNotification(String title, String message) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "MyNotifitcation")
.setContentTitle(title)
.setSmallIcon(R.drawable.logo)
.setAutoCancel(true)
.setContentText(message);
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(999, builder.build());
}
解决方案
如果您想在应用程序的另一部分显示通知,您可以将通知存储在本地数据库(领域、房间、sqlite)中,然后制作一个显示来自数据库的通知的屏幕。
如果你想做一个快速的概念证明,你可以存储在内存中,在一个单例中(仅用于快速的概念证明,请不要到处使用单例)。
推荐阅读
- javascript - 如何在 Reactjs 中正确渲染数组中的元素?
- spring-boot - Docker:在运行时更改端口号
- laravel - 如何在 Laravel 的 whereIn 中使用别名列?
- node.js - onTeamsMemberAddedEvent() 不适用于个人范围
- python - (discord.py) 检查消息是否包含列表中的元素的正确方法是什么?
- java - 安装时找不到 mvn
- html - 使用 role="button"在标签上水平居中标题文本
- validation - 属性之间的 OpenAPIV3 条件验证?
- python-3.x - Cloud Foundry 应用程序中的 Selenium 网络爬取
- json - 如何将 JSON 字符串序列化为多维 NSDictionary