Android 外部应用程序安装(在 SD 卡上),通过接收器重新安装时重新加载 Alarmmanager 警报
我正在开发一个 Android 应用程序,我希望允许用户将其安装在他们的 SD 卡上(http://developer.android.com/guide/appendix/install-location.html)。但是,该应用程序有一些通过 AlarmManager 创建的警报。根据Android开发人员指南(我包含的链接),如果卸载了安装应用程序的外部媒体(SD卡),则会发生以下情况:“您使用AlarmManager注册的闹钟将被取消。您必须手动重新安装外部存储时重新注册所有警报。”
有什么方法可以“唤醒”我的应用程序,以便在重新安装 SD 卡时重新安排闹钟?也许使用带有意图过滤器的接收器?我尝试为 android.intent.action.MEDIA_MOUNTED 添加接收器,但这不起作用(可能是因为外部安装的应用程序没有获得该意图广播,或者因为应用程序二进制文件在安装媒体后不立即可用,并且意图被广播?)。有人可以提出任何其他意图吗?或者还有其他方法可以做到这一点? android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE 意图(http://developer.android.com/reference/android/content/Intent.html#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)似乎是我所需要的,但文档说外部媒体上的应用程序不会得到这个意图。
I'm developing an android app that I want to allow users to install on their SD card (http://developer.android.com/guide/appendix/install-location.html). However, the app has some Alarms created through AlarmManager. According to the android developers guide (the link I've included), if the external media (SD card) that the app is installed on is unmounted, the following will happen: "Your alarms registered with AlarmManager will be cancelled. You must manually re-register any alarms when external storage is remounted."
Is there some way I can "wake" my app up so that I can re-schedule the alarms when the SD card is remounted? Maybe use a receiver with some intent filter? I tried adding a receiver for android.intent.action.MEDIA_MOUNTED, but that didn't work (maybe because apps installed externally don't get that intent broadcast, or because the app binaries aren't available immediately after media is mounted and that intent is broadcasted?). Any other intents someone can suggest? Or some other way to do this? The android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE intent (http://developer.android.com/reference/android/content/Intent.html#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE) seems like what I'd need, but the docs say the apps on the external media will not get this intent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前没有解决方法:要么强制您的应用程序只能安装在内部存储器上,要么实现一个附加应用程序保留在内部存储器中并处理您的警报。
Currently no workaround for this: either force your app to only be installable on internal memory or implement an add-on application that stays in internal memory and handles your alarms.
不认为这是可能的,请参阅 什么无法在 SD 卡上工作 这看起来相当蹩脚,但如果没有非 SD 卡服务来监视安装/卸载条件,这也有点蹩脚,这似乎不可能。
不将主应用程序放在 SD 卡上的另一个原因是,如果用户将硬盘驱动器连接到 PC,则 USB 电缆也可能导致存储卸载等。
Don't think this is possible see What doesn't work on a sdcard This seems pretty lame but without a non-sdcard service to monitor mount/unmount conditions, which would also be kind of lame, it does not seem possible.
Yet another reason not to put the main app on the sdcard, usb cable can also cause the storage to unmount etc. if the user connects as a hard drive to a pc.