简体   繁体   English

从代码启动.apk

[英]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. 它从某个位置下载文件,然后启动此意图以运行.apk。 Unfortunately, when I do it, it gives me the error "there is a problem parsing the package android studio". 不幸的是,当我这样做时,它给我一个错误“解析android studio包时出现问题”。

If I navigate to the download path, and run the .apk manually, it works just fine to install. 如果我导航到下载路径,然后手动运行.apk,则可以很好地进行安装。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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