简体   繁体   中英

Launching .apk from Code

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

So, I am creating an application that checks for updates on launch. it downloads a file from a location, and then launches this intent to run the .apk. Unfortunately, when I do it, it gives me the error "there is a problem parsing the package android studio".

If I navigate to the download path, and run the .apk manually, it works just fine to install.

Any ideas?

Try this one:

File apkFile = new File(Environment.getExternalStorageDirectory()
                  .getAbsolutePath() + "/app-release.apk");
Intent install_intent = new Intent(Intent.ACTION_VIEW);
install_intent.setDataAndType(Uri.fromFile(apkFile), 
     "application/vnd.android.package-archive");
startActivity(install_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