3

As of 4.2, using the following code to install an APK, the install fails if the APK version is lower than the currently installed version. Is there a PutExtra() that will allow the downgrade?

File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);

Or do I need to do it a different way?

NebulaSleuth
  • 833
  • 1
  • 7
  • 18
  • I am not aware of a way to support downgrades in general, except by uninstalling the app, or installing via **`adb`** (for developers). – CommonsWare Sep 21 '13 at 17:18
  • 1
    I never managed to downgrade an installed app even with adb :-/ The only solution I know of is uninstalling the app first. It is also very reasonable because private settings and persistent data layouts may change from version to version. An older version of an app is unlikely to cope with data changes in newer versions. – tiguchi Sep 21 '13 at 17:30
  • 1
    when using pm from the command line in 4.2 there is a -d option to allow downgrades. I want to do the same thing when launching the install from my application – NebulaSleuth Sep 21 '13 at 18:36
  • If this has upset your enterprise customers as much as it has mine, star the issue here: https://code.google.com/p/android/issues/detail?id=62545 – Kevin Krumwiede Jun 04 '14 at 18:42

2 Answers2

0

AFAIK the allowing downgrades is the function of application is being install if this app allows to be downgraded the it will downgrade the currently installed app otherwise you can't

so from your Intent you can not control it

The setting you can set in your application

This property you can set in your manifest

This property

Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
  • 1
    I am using Mono for android, so the "Restore needs application" option does not exist in the IDE. But adding android:restoreAnyVersion="true" to the section in the androidmanifest.xml did not resolve the issue in Android 4.2. Is there other options I need in the manifest? – NebulaSleuth Sep 21 '13 at 19:17
0

At least with same versionname / versioncode works following extra to the intent (for me (Android 4.2.2, Galaxy S4 Active):

Uri uri = Uri.fromFile(new File(PATH_TO_FILE_APK));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra('Intent.ACTION_PACKAGE_REPLACED', "your.package.name");
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);

In my case, this restarts the app after replacing.

Bondax
  • 3,143
  • 28
  • 35