【发布时间】:2018-06-04 02:15:42
【问题描述】:
我正在尝试使用 FileProvider 概念从我的应用程序访问保存在 Download\AppName\myApk.apk 中的 apk 文件,但失败了
我正在使用以下代码
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
File file = new File(location);
// location= Environment.getExternalStorageDirectory() + "/Download/AppName\MyApk.apk";
Uri uri = FileProvider.getUriForFile(Login.this, BuildConfig.APPLICATION_ID + ".fileprovider", file);
intent.setData(uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, INSTALL_APK_REQUEST_CODE);
清单
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="xxx.xxx.xxx.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths"/>
</provider>
filePath.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="adbc" path="Download/AppName" />
</paths>
例外
Failed to find configured root that contains /storage/emulated/0/Download/AppName/MyAPk.apk
请帮忙!!!
【问题讨论】:
-
请编辑您的问题并提供完整的 Java 堆栈跟踪。
-
请注意,您添加了错误消息,而不是堆栈跟踪。碰巧这一次,错误信息就足够了。将来,当您在 Stack Overflow 上询问涉及崩溃的问题时,请发布整个堆栈跟踪,因为您的困难的根源可能在于该跟踪的更深处,而不仅仅是顶行。
标签: java android android-7.0-nougat android-fileprovider