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

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

【问题讨论】:

    标签: android service notifications persistent


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

    【讨论】:

    • 说,时间...当用户打开通知幻灯片时,他会看到当前时间。有可能吗?
    猜你喜欢
    • 2017-11-06
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多