android - 来自服务的持久性 android 通知

标签 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?很抱歉没有重新发布他的答案,但它包含很多代码,可以帮你解决问题。

关于android - 来自服务的持久性 android 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14320631/

相关文章:

java - 从 Android 中的 Assets 传递路径

android - ActionBarSherlock SearchView 转换错误

android - 从通知按钮取消服务

Android:启动时启动服务?

Android 服务未在后台正常运行

ajax - 使用 ajax 添加到购物车时如何添加 Woocommerce 通知(无需重新加载)?

android - 底部导航 View 不显示图标或标题

android - 需要更新服务版本?

android - 通知 "setContentInfo"未显示

wcf - WPF/WCF 推送通知