【发布时间】:2013-01-14 14:47:07
【问题描述】:
如何制作持久通知,每次用户看到它时都会更新? 形成服务
【问题讨论】:
标签: android service notifications persistent
如何制作持久通知,每次用户看到它时都会更新? 形成服务
【问题讨论】:
标签: android service notifications persistent
要在Service 运行时显示通知,请调用:
startForeground(R.string.notification_id, myNotification);
为该方法提供您的服务的 ID,以及您创建的 Notification。
在任何时候,您的Service 都可以通过使用相同的R.string.notification_id 并发布新的Notification 来更新用户看到的内容:
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(R.string.notification_id, myNotification);
要创建Notification,您需要阅读Notification.Builder (android docs here)。
关于一个相关问题也有一个很好的答案:How exactly to use Notification.Builder? 很抱歉没有重新发布他的答案,但它包含很多代码,会帮你解决。
【讨论】: