【发布时间】:2021-05-05 16:11:34
【问题描述】:
我使用存储访问框架将文档保存到磁盘。有没有办法使用 Intent 与其他应用共享该特定文档文件?
我使用以下方法分享:
fun Activity.sharePdf(pdfUri: Uri) {
var intent = Intent(Intent.ACTION_SEND)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val uri =
FileProvider.getUriForFile(
this,
this.packageName.toString() + ".provider",
File(pdfUri.toString())
)
intent.type = "application/pdf";
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
} else {
intent.type = "application/pdf";
intent.putExtra(Intent.EXTRA_STREAM, pdfUri.toString())
intent = Intent.createChooser(intent, "Open File")
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
}
这不适用于使用 SAF 存储的文件。
【问题讨论】:
标签: storage-access-framework scoped-storage