Enable downgrade when installing apk using Android 4.2+ intent

Is it possible to enable downgrade when installing apk using intent on Android 4.2+? I found out that this is possible when installing the application through the shell (using -d) adb install -r -d <link to apk> , so I hope this is possible through Intent as well. I was looking for some kind of flag or something like that, but I did not find anything useful.

This is my intention to open the package installer:

 Intent intent = new Intent(Intent.ACTION_VIEW); Uri applicatonFileUri = Uri.fromFile(applicationFile); intent.setDataAndType(applicatonFileUri, PACKAGE_TYPE); startActivity(intent); 
+7
android android-intent apk android-package-managers
source share
2 answers

This is not possible for applications other than the platform (third-party): you must make a request to install PackageManager directly.

PackageManager has a non-public API, installPackage () (line 2584 at the time of this writing):

 /** * @hide * * Install a package. Since this may take a little while, the result will * be posted back to the given observer. An installation will fail if the calling context * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the * package named in the package file manifest is already installed, or if there no space * available on the device. * * @param packageURI The location of the package file to install. This can be a 'file:' or a * 'content:' URI. * @param observer An observer callback to get notified when the package installation is * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be * called when that happens. observer may be null to indicate that no callback is desired. * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK}, * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}. * @param installerPackageName Optional package name of the application that is performing the * installation. This identifies which market the package came from. */ public abstract void installPackage( Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName); 

where one of the possible INSTALL_ALLOW_DOWNGRADE flags is:

 /** * Flag parameter for {@link #installPackage} to indicate that it is okay * to install an update to an app where the newly installed app has a lower * version code than the currently installed app. * * @hide */ public static final int INSTALL_ALLOW_DOWNGRADE = 0x00000080; 

All of these APIs are hidden and inaccessible to third-party applications. Now you can try to think, but I'm pretty sure that the platform will still restrict their access.

+11
source share

Another possible solution is to have another application that first uninstalls your application and then installs it again. I could not find another way, if someone finds a better solution, let me know :)

0
source share

All Articles