Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reinstall application apk programmatically without downloading

Tags:

java

android

Due to this annoying Android limitation I need users to reinstall my application so the manifest permissions are detected by other applications.

This is already going to be frustrating for the user, but in addition, I cannot see a way to reinstall my application from the apk stored in /data/app and I would therefore have to download the same version to the storage card before firing the usual install intent.

I eagerly await someone telling me that I'm missing something obvious! I've drawn a blank...

Thanks in advance.

Please do star the issue if you'd like to see it resolved! Cheers.


EDIT: With the comments of @hackbod in mind, you can use the following code to initiate the install dialog.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(this.getApplicationInfo().sourceDir)),
"application/vnd.android.package-archive");
startActivity(intent);

On my Jelly Bean device, this presents two options: Package installer and Verify and install. I don't know if the latter will deal with the issue of:

  • Installing your app this way will probably remove ownership of it from the Play Store

My application is free, so I cannot test the paid issue of:

  • Note however if your app is forward locked (which is unavoidable for all paid applications starting with JB, due to the app encryption), then this won't work because your app executable is not readable by others

Although hackbod finishes with 'readable by others' which suggests that if you are executing this through your own code, for your own application, it is readable? Please do correct me if you can test this and I'm wrong.

like image 207
brandall Avatar asked May 16 '12 14:05

brandall


1 Answers

Conceivably you could just get the path to your .apk through Context.getApplicationInfo().sourceDir, and launch the app installer with that path. Not however if your app is forward locked (which is unavoidable for all paid applications starting with JB, due to the app encryption), then this won't work because your app executable is not readable by others. In that case you would need to copy the .apk to somewhere world readable (such as in external storage) and install it from there.

No matter what you do here, though, this has some unavoidable very negative consequences:

  • The only way to do any kind of install from your app is to go through the side-loading UI, which is (a) going to be a very scary experience for the user, and (b) will require that the user turn on side-loading to be able to proceed.
  • Installing your app this way will probably remove ownership of it from the Play Store (since it is no longer the one that has installed it). This may mean for example that the user can no longer report crashes or ANRs to you through the play store, or other negative consequences. I am not sure exactly what problems will actually happen here, but I really wouldn't assume that this is going to be okay.

Ultimately, I just would very much not suggest doing this. What permission are you needing that is forcing you to do this? For many reasons, I wouldn't recommend that third party applications declare their own permissions in most cases, because there are a lot of bad user experiences around permissions that are only known after they may have been needed.

like image 60
hackbod Avatar answered Oct 18 '22 13:10

hackbod