android - 无法在第三方应用程序中打开 Zip 文件
问题描述
我正在尝试加载下载到context.getFileDir()
第三方应用程序中的 zip 文件
第三方的结果是“*No files are selected *” 我试图检查 zip 文件是否下载成功,所以我已经从代码中解压缩它,它似乎下载正确,应该在外部第三方中打开党的申请。
我已将 Provider 放入清单以导出 URI
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:resource"
android:resource="@xml/provider_paths"/>
</provider>
而我的道路
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="internal" path="." />
</paths>
这就是我想要做的事情
File file = FileHelper.GET_FILE(material);
try {
unzip(file);
} catch (IOException e) {
e.printStackTrace();
}
Uri uri = FileProvider.getUriForFile(material.getContext(), material.getContext().
getApplicationContext().getPackageName() +
".provider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/zip");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
material.getContext().startActivity(intent);
解决方案
似乎我忘记将此标志添加到意图中
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
添加此标志后,一切正常
推荐阅读
- html - 如何在 robots.txt 中禁用搜索引擎索引的 .htm、.html 链接
- python - how do you print a receipt using Star TSP 650 II?
- python - How to combine two loops in the same excel page for xlsxwriter
- go - 将循环的 int 打印为字符串
- javascript - 打字稿对象按键排序
- php - 如何仅自动显示基于本月的数据?
- vue.js - vuetify v-select:样式。去掉下划线,自定义占位符
- laravel - Laravel 8通过Gmail发送邮件获取stream_socket_client():无法连接到tcp://smtp.gmail.com:587(连接超时)
- python-3.x - 在 Python 中检查两个字符串列是否相互包含
- sql - VBA - 将字符串转换为日期时间以与 SQL 中的日期进行比较