2

I need to install apk programatically. I find a method to install it with Intent: install / uninstall APKs programmatically (PackageManager vs Intents)

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Download/" + "app.apk"));
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
startActivity(intent);

But, it doesn't work. The problem is the installation activity didn't appear, instead, a list of other programs is displayed for choice:

enter image description here

Could someone tell me what the problem is? Thanks!

Update:

  1. The permission android.permission.INSTALL_PACKAGES is included in manifest.
  2. I am running Android version 2.3 SDK 10
Community
  • 1
  • 1
Dagang
  • 24,586
  • 26
  • 88
  • 133

1 Answers1

4

Maybe this will solve your problem:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
startActivity(intent);  
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
deepak Sharma
  • 1,641
  • 10
  • 23