// Request code for creating a PDF document.const val CREATE_FILE = 1private fun createFile(pickerInitialUri: Uri) {val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {addCategory(Intent.CATEGORY_OPENABLE)type = "application/pdf"putExtra(Intent.EXTRA_TITLE, "invoice.pdf")// Optionally, specify a URI for the directory that should be opened in// the system file picker before your app creates the document.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)}startActivityForResult(intent, CREATE_FILE)}2)打开文档
建议使用 type 设置 MIME 类型
// Request code for selecting a PDF document.const val PICK_PDF_FILE = 2fun openFile(pickerInitialUri: uri) {val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {addCategory(Intent.CATEGORY_OPENABLE)type = "application/pdf"// Optionally, specify a URI for the file that should appear in the// system file picker when it loads.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)}startActivityForResult(intent, PICK_PDF_FILE)}3)授予对目录内容的访问权限
用户选择目录后 , 可访问该目录下的所有内容
推荐阅读
- Android Camera 内存问题剖析
- 详解Apache Hudi如何配置各种类型分区
- 兰贵人茶存储方法,兰贵人茶的功效兰贵人茶的禁忌
- Android Jetpack架构组件Navigation管理Fragment框架
- IDE 最佳Android应用程序开发工具
- Windows10还需要分区吗?看完你就有答案了
- Android WebView 优化梳理
- Android 性能优化——内存优化
- 回南天茶叶如何存储,如何快速的检测茶叶含水量
- 老茶存储误区,品茶五大误区
