来自服务的持久 android 通知

Posted

技术标签:

【中文标题】来自服务的持久 android 通知【英文标题】:Persistent android notification from service 【发布时间】:2013-01-14 14:47:07 【问题描述】:

如何制作持久通知,每次用户看到它时都会更新? 形成服务

【问题讨论】:

【参考方案1】:

要在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? 很抱歉没有重新发布他的答案,但它包含很多代码,会帮你解决。

【讨论】:

说,时间...当用户打开通知幻灯片时,他会看到当前时间。有可能吗?

以上是关于来自服务的持久 android 通知的主要内容,如果未能解决你的问题,请参考以下文章