简体   繁体   中英

Android install apk with Intent

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:

在此处输入图片说明

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

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);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM