问题
I know about the ACTION_MY_PACKAGE_REPLACED Intent action but what it do is - notifies the receiver AFTER the app got replaced.
But the things is - I want to know before the app is being replaced by another.
I tried with these actions
<receiver
android:name=".receivers.InstallReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
but doesn't help!
回答1:
I want to know before the app is being replaced by another
That is not possible, sorry.
What if I want to stop some service before the app got uninstalled?
When an app is replaced or removed, its process is terminated. The process will be terminated for many other reasons as well (e.g., old age, Force Stop in Settings). There should be no need to do something special for the replacement/uninstall scenario.
来源:https://stackoverflow.com/questions/47391915/is-there-any-way-to-get-notified-before-the-app-is-being-replaced-by-another