That’s it. Generally speaking, the process of installing a third-party app is that the user or other application triggers the original apk file on the sdcard to install. The system installation process will copy the apk to the /data/app directory for installation, and This path can be queried by all applications. Part of the so-called system restart is to reinstall all applications in the /data/app directory. So if the poster wants to delete it, it is basically equivalent to uninstalling his own app.
Of course, you can monitor the installation of the app and delete the original apk file on the sdcard.
If it is an automatic update, you can definitely control the file download location. Now that you can control the file download location yourself, it is easy to delete a file at a specified location.
I don’t know where the difficulty lies. Maybe I missed something?
New versions have a first-time startup tag (used for boot pages and the like). Use it to control whether this version is installed for the first time. Then delete it according to the method above.
Listen to system application installation or update broadcasts <action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" /> The last line must be added, and then from the obtained Intent Extract the package information, intent.getDataString(), see if it is yours, and then delete it
That’s it. Generally speaking, the process of installing a third-party app is that the user or other application triggers the original apk file on the sdcard to install. The system installation process will copy the apk to the /data/app directory for installation, and This path can be queried by all applications. Part of the so-called system restart is to reinstall all applications in the /data/app directory. So if the poster wants to delete it, it is basically equivalent to uninstalling his own app.
Of course, you can monitor the installation of the app and delete the original apk file on the sdcard.
You need to meet two points:
1. Your app needs to be started after installing the update
2. You need to know the path of the apk
If it is an automatic update, you can definitely control the file download location.
Now that you can control the file download location yourself, it is easy to delete a file at a specified location.
I don’t know where the difficulty lies. Maybe I missed something?
New versions have a first-time startup tag (used for boot pages and the like). Use it to control whether this version is installed for the first time. Then delete it according to the method above.
Listen to system application installation or update broadcasts
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
The last line must be added, and then from the obtained Intent Extract the package information, intent.getDataString(), see if it is yours, and then delete it