java - 获取存储中的 pdf 文件列表 - Mediastore android
问题描述
有人可以帮我解决这个问题吗,我想从外部存储中获取 pdf 文件列表,但数组总是空的,这是我的代码:
先感谢您。
这是我的代码:
public static ArrayList<String> getPdfFiles(Context context) {
ArrayList<String> listOfAllFiles = new ArrayList<>();
Uri uri = MediaStore.Files.getContentUri("external");
ContentResolver cr = context.getContentResolver();
String[] projection = {MediaStore.MediaColumns.DATA};
// only pdf
String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
String[] selectionArgsPdf = new String[]{ mimeType };
Cursor allPdfFiles = cr.query(uri, projection, selectionMimeType, selectionArgsPdf, null);
while (allPdfFiles.moveToNext()) {
int nameIndex= allPdfFiles.getColumnIndex(MediaStore.Files.FileColumns.TITLE);
String name= allPdfFiles.getString(nameIndex);
listOfAllFiles.add(name);
}
return listOfAllFiles;
}
解决方案
推荐阅读
- go - “x509.DecryptPEMBlock”已弃用,有什么替代方案?
- oracle - 一段时间内我能得到谁的所有解释计划?
- c++ - 在数组元素中添加数字
- python - Lambda AWS Powertools 事件验证错误
- python - 如何从 Parquet 文件中获取确切的数据类型写入 PySpark 中的 Csv 文件
- video-streaming - 包含视频的画布大小和流式传输视频的质量
- html - 动态365全渠道客服的ChatWidget无法加载?
- python - pd.replace 未按预期运行
- typescript - 省略助手不适用于映射对象类型
- tensorflow - 如何使用 TensorFlow 的子分类方法预测二进制分类的类?