要在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?抱歉没有重新发布他的答案,但它包含了很多代码,并会将你排除在外.
| 归档时间: |
|
| 查看次数: |
1931 次 |
| 最近记录: |