如何知道我的Android应用程序已经升级,以重置报警? [英] How to know my Android application has been upgraded in order to reset an alarm?
问题描述
我注意到,当它设置该报警的应用程序已经升级了报警将被禁止。 是这样吗?
I noticed that an alarm is disabled when the application which sets this alarm has been upgraded. Is that true ?
到现在为止,我使用了共享preferences
与 FIRST_RUN
FIRST_RUN 来假的,别的我什么也不做。
Until now, I used the SharedPreferences
with a FIRST_RUN
key in order to know if it's the first run of my application. If I don't find this key, I enable the alarm and set FIRST_RUN
to false, else I do nothing.
但是,我也注意到,这些preferences保持完整的应用程序升级的!
But I noticed also that these preferences remain intact between app upgrade !
所以,在升级之后,该 FIRST_RUN
键已经是假的,所以我什么都不做,而我的报警需要激活。
So after an upgrade, the FIRST_RUN
key is already false, so I do nothing while my alarm need to be enabled.
如何处理这种情况?
在此先感谢
推荐答案
我从来没有尝试这个自己,但如何创建一个的BroadcastReceiver
监听到<一个href="http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REPLACED"><$c$c>ACTION_PACKAGE_REPLACED$c$c>意图是什么?
I've never tried this myself, but what about creating a BroadcastReceiver
that listens to the ACTION_PACKAGE_REPLACED
Intent?
我想过之前尝试这一点,但我不知道是否有鸡还是先有蛋的问题,或不(例如,莫非是意图在新升级的应用程序可以接收之前就被送进?)。值得一试,虽然。
I've thought about trying this before, but I'm not sure if there's a chicken-and-egg problem with it or not (e.g., does the Intent get sent before the new upgraded application can receive it?). Worth a try, though.
这篇关于如何知道我的Android应用程序已经升级,以重置报警?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!