简体   繁体   English

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

[英]How to run install app in internal files dir?

I have some lines of code and apk file in internal cache dir: 我在内部缓存目录中有一些代码行和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);

But I had a parsing error: "There was a problem parsing the package" 但是我遇到了一个解析错误:“解析软件包时出现问题”

Thank You for helping! 感谢您的帮助!

Third-party apps, including the package installer, have no access rights to that file. 第三方应用程序(包括软件包安装程序)没有对该文件的访问权限。

On Android N, they have finally fixed the problem with installing apps via a ContentProvider , like FileProvider . 在Android N上, 他们终于解决了通过ContentProvider (例如FileProvider 安装应用程序的问题 For versions prior to that, you can install from external storage , or maybe use MODE_WORLD_READABLE (deprecated, and banned on Android N) to allow that file to be read from internal storage . 对于之前的版本,您可以从外部存储安装,也可以使用MODE_WORLD_READABLE (已弃用,并在Android N上禁止使用)以允许从内部存储读取该文件。

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

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