Android - 应用更新后警报丢失 [英] Android - Alarm lost after app update

查看:24
本文介绍了Android - 应用更新后警报丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Android 上运行的应用程序,它会创建一个每 24 小时触发一次的警报.此警报按预期工作.

I have an app running on Android that creates an alarm that is fired every 24 hours. This alarm is working as expected.

但是,当我通过 Google Play 更新我的应用时,此警报会丢失,因为最终用户在应用更新后并未立即打开应用.

However, when I update my app through Google Play this alarm is lost because the end user does not open the app right after the app was updated.

我的观点是 Android 正在删除我的应用在更新应用时创建的警报.

My opinion is that Android is deleting the alarms my app created when the app was updated.

有人遇到过这种情况吗?有没有办法在应用更新时保持警报?

Does anyone already got this situation? Is there any way to persist the alarms when the app is updated?

推荐答案

你的解决方案很简单:

在您的应用中注册一个广播接收器,其中包含 2 个 Intent 过滤器:

Have a broadcast receiver registered within your app with 2 intent filters namely:

  1. "android.intent.action.BOOT_COMPLETED" - 设备重启时调用.设备关闭时,警报会被取消.
  2. "android.intent.action.MY_PACKAGE_REPLACED" - 在您的应用重新安装或从 Play 商店或任何来源更新后调用.

您还需要android.permission.RECEIVE_BOOT_COMPLETED"权限.在此接收器中,您可以再次启动闹钟.

You will also need the permission, "android.permission.RECEIVE_BOOT_COMPLETED". In this receiver you can start your alarms again.

这篇关于Android - 应用更新后警报丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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