[英]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);
因此,我正在创建一个在启动时检查更新的应用程序。 它从某个位置下载文件,然后启动此意图以运行.apk。 不幸的是,当我这样做时,它给我一个错误“解析android studio包时出现问题”。
如果我导航到下载路径,然后手动运行.apk,则可以很好地进行安装。
有任何想法吗?
试试这个:
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.