Android:在手机重启后保持通知 [英] Android: make notification persist across phone reboot

查看:20
本文介绍了Android:在手机重启后保持通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在手机关机后再开机时保持状态栏通知的最佳方法是什么?我能想到的唯一解决方案是在响应 BOOT_COMPLETED_ACTION 意图的服务中创建通知.

What's the best way to have a status bar notification persist when the phone is turned off and on again? The only solution I can think of is to create the notification in a Service which starts in response to the BOOT_COMPLETED_ACTION Intent.

推荐答案

我能想到的唯一解决方案是在响应 BOOT_COMPLETED_ACTION 意图而启动的服务中创建通知.

The only solution I can think of is to create the notification in a Service which starts in response to the BOOT_COMPLETED_ACTION Intent.

对于引发 Notification,您可能只需在 BOOT_COMPLETED_ACTION BroadcastReceiver 中执行它,而不是将其委托给服务.但是,我同意,这是 AFAIK 的唯一方法.

For raising a Notification, you can probably get by with just doing it in the BOOT_COMPLETED_ACTION BroadcastReceiver, rather than delegating it to a service. However, I agree, this is the only way to do it AFAIK.

请确保您这样做不会激怒您的用户.大多数人在重新启动手机时都期望相对干净.Android 假定通知不再与重启相关,这就是它们不会持续存在的原因.

Just be sure you do not irritate your users by doing this. Most people expect a relatively clean slate when they reboot their phone. Android assumes that notifications are no longer relevant with a reboot, which is why they do not persist.

因此,例如,假设您正在编写电子邮件客户端,并且您使用通知让用户了解未读邮件.答案不应是重新启动后重新显示未读消息通知".答案应该是重新启动后检查未读消息,如果有未读消息则发出通知".这样,如果没有未读消息(例如,用户关闭手机一段时间并在 PC 或平板电脑上处理电子邮件),他们就不会收到虚假通知.

So, for example, suppose you were writing an email client, and you use notifications to let the user know about unread messages. The answer should not be "redisplay the unread-message notification after a reboot". The answer should be "check for unread messages after a reboot, and raise the notification if there are unread messages". This way, if there are no unread messages (e.g., user had the phone off for a while and took care of their email on their PC or tablet), they do not get a spurious notification.

这篇关于Android:在手机重启后保持通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆