java - 如何通过隐式意图创建内容提供程序以将 PDF 文件共享到另一个应用程序?
问题描述
我正在为我的学校制作项目。在这个应用程序中,我从 Firebase 下载 pdf 文件并将其存储在应用程序的外部目录中。下载后,我想通过隐式意图到其他pdf阅读器应用程序来显示下载的pdf。我直接在网上搜索了 2 天以了解如何创建内容提供程序,但所有教程都是旧的并且使用了 android.support.v4 内容提供程序,我不知道如何创建自定义内容提供程序。我尝试使用 androidx.core.content.fileprovider 并且它还创建了内容 uri,但是在启动时,会弹出 pdf 阅读器屏幕但没有显示任何内容,只显示文件的标题。
fileUri.toString-content://com.syrous.studentlibraryjava.fileprovider/document/mse1_dagaeg.pdf 的输出
Uri fileUri = getUriForFile(getApplicationContext(), getPackageName()+".fileprovider", localFile); //This is the in build function, just accepted import.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(fileUri, "application/pdf");
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
这是manifest中provider的声明---->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.syrous.yccestudentlibraryjava.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
这是file_paths ----->
<paths>
<external-files-path
name="document"
path="mse1/"/>
</paths>
我不确定,如果我声明 file_path 正确。我在 external_folder/files/mse1/file_to_open 中有我的 pdf 文件。如果 file_path 有任何更正,请建议我。
我有权读取和写入清单中声明的外部存储,并且还要求它
帮帮我吧伙计们!! 模拟器图像
解决方案
android:authorities="com.syrous.yccestudentlibraryjava.fileprovider
does not mach content://com.syrous.studentlibraryjava.fileprovider/document/mse1_xfaefga.pdf
.
推荐阅读
- android - 使用 Camera2 API Kotlin 单击图像时出现白色图像
- sql - 通过检测名称动态填充 SQL 表?
- git - 在长期运行的樱桃采摘分支中禁用整个合并
- mysql - macOS:zsh:找不到命令:mysqldump
- python-3.x - 异常值:_getfullpathname:路径应该是字符串、字节或 os.PathLike,而不是列表
- php - (已解决)无法让 php 与 nginx 一起运行//无论我尝试什么,我都会得到 502 Bad Gateway
- python - 想要使用嵌套字典在输出控制台打印内部字典的所有键和值
- flutter - 抛出异常时,快照会包含错误吗?
- batch-file - 当我调用一个应该启动一个程序的函数时,为什么我的所有程序都打开了?
- javascript - 如何为同一行中的不同单元格设置不同的字体颜色?