安卓:跨手机重启做出通知仍然存在 [英] Android: make notification persist across phone reboot

查看:191
本文介绍了安卓:跨手机重启做出通知仍然存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是有当手机关机并重新状态栏通知坚持的最好方法是什么?唯一的解决办法我能想到的是,在开始响应 BOOT_COMPLETED_ACTION 意图服务创建通知。

解决方案
  

唯一的解决办法我能想到的是,在开始响应BOOT_COMPLETED_ACTION意图服务创建通知。

有关抚养通知,你也许可以得到通过只是在做它在 BOOT_COMPLETED_ACTION 的BroadcastReceiver ,而不是将其委托给服务。不过,我同意,这是AFAIK做到这一点的唯一方法。

只要确保你不这样做,刺激你的用户。大多数人期待一个相对干净的石板,他们重新启动他们的电话时。 Android的假设通知不再与有关重新启动,这就是为什么他们不坚持。

因此​​,举例来说,假设你在写一个电子邮件客户端,并使用通知让用户知道未读邮件。答案不应该重新显示重新启动后未读消息的通知。答案应该是重新启动后,检查是否有未读邮件,并提高该通知,如果有未读邮件。这样一来,如果没有未读信息(例如,用户不得不将手机关机一段时间,照顾他们的电子邮件的他们的PC或平板电脑上),他们没有得到一个虚假的通知。

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.

解决方案

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.

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.

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.

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.

这篇关于安卓:跨手机重启做出通知仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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