1

I used to have this problem but I found a solution, so just decided to post it here just in case someone else needs it.

How to launch the native installer app to install an apk?

Many posts have the solution as below:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive");
context.startActivity(intent);

This is fine except a tiny but crutial detail:

the "path" string must start with file:// otherwise you'll get an exception such as

Unable to find an activity to handle the intent .....

So make sure the path starts with file://

Cheers.

Nar Gar
  • 2,591
  • 2
  • 25
  • 28
  • possible duplicate of http://stackoverflow.com/questions/9637629/can-we-install-an-apk-from-a-contentprovider – CommonsWare May 02 '12 at 11:07
  • @CommonsWare - your link does indeed contain this information, however does not put stress on the importance of "file://" scheme. Thanks for the link by the way, I wish I could find it earlier - would save me a bunch of grey hair :) – Nar Gar May 03 '12 at 01:35

1 Answers1

1

Actually, instead of using the parse(...) method, you can simply use the fromFile(...) method of the Uri class (the Uri will automatically have the form "file://").

Thus:

final File file = new File(path);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
context.startActivity(intent);
Paolo Rovelli
  • 9,396
  • 2
  • 58
  • 37