【发布时间】:2022-01-19 05:56:27
【问题描述】:
我无法仅在 android 12 中使用 Intent 共享 PDF,但它在低于版本的情况下工作正常。正在下载文件并从下载文件夹中获取文件 Uri。
下载位置:
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
错误信息:分享失败,请重试。
private void sharePDF() {
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", pdfFile);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, fileUri);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setType("application/pdf");
startActivity(Intent.createChooser(share, "Share Catalogue"));
}
【问题讨论】:
-
帮助我或建议代码 sn-p 或博客链接