【发布时间】:2019-03-12 13:24:55
【问题描述】:
我正在尝试在 android 应用中读取 pdf 文件。
触发以下意图以获取 URI。
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, PDF_FILE_SELECTOR_INTENT_ID);
问题是,Downloads 文件夹还显示了我已删除的旧文件。
此外,当我选择这些文件时,onActivityResult() 中会返回一个有效的URI。当我从URI 创建File 并检查exists() 时,它会返回false,因为我已经从Downloads 文件夹中删除了该文件。
如何确保ACTION_GET_CONTENT 上显示的Downloads 文件夹仅显示当前存在的文件而不是已删除的文件?
谢谢。
【问题讨论】:
-
This is the intented behavior。 URI(s) 不会立即更新,因此,它们可能指向 null、不存在甚至不同类型的目标(音频、图像等)
-
您不需要内容提供商为您执行此操作吗?
-
您在哪个设备上进行测试。什么是android os版本?
标签: android file android-intent android-contentprovider