如何知道我的Android应用程序已经升级,以重置报警?
我注意到,当它设置该报警的应用程序已经升级了报警将被禁止。 是这样吗?
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
监听到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.