Is there any way to get notified before the app is

2019-08-19 00:19发布

问题:

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.