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
  • 22,175
  • 25
  • 78
  • 116

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
  • 82,434
  • 38
  • 201
  • 248
deepak Sharma
  • 1,631
  • 9
  • 23