来自服务的持久性android通知

acl*_*kay 1 service notifications android persistent

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

Ric*_*ier 6

要在Service运行时显示通知,请致电:

    startForeground(R.string.notification_id, myNotification);
Run Code Online (Sandbox Code Playgroud)

为该方法提供您的服务ID以及您Notification创建的ID .


在任何时候,您Service都可以使用相同的内容更新用户看到的内容R.string.notification_id并发布新内容Notification:

    NotificationManager notificationManager = 
        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(R.string.notification_id, myNotification);
Run Code Online (Sandbox Code Playgroud)

要创建一个Notification,你需要阅读Notification.Builder(这里的android文档).

在一个相关问题上也有一个很好的答案:如何使用Notification.Builder?抱歉没有重新发布他的答案,但它包含了很多代码,并会将你排除在外.