如何在内部文件dir中运行安装应用程序?

时间:2016-04-20 21:13:33

标签: android install apk

我在内部缓存目录中有一些代码和apk文件:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(newFile(context.getCacheDir() + "/update.apk")), "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

但我有一个解析错误:“解析包时遇到问题”

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

第三方应用程序(包括程序包安装程序)对该文件没有访问权限。

在Android N上,they have finally fixed the problem with installing apps via a ContentProvider,与FileProvider一样。对于之前的版本,您可以从external storage安装,或可能使用MODE_WORLD_READABLE(已弃用,并在Android N上禁用)以允许从{{ 3}}