我找到了有关如何获取所有图像的代码。
有人可以告诉我如何在内部存储和外部存储中仅获取.pdf文件吗?
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;
//Stores all the images from the gallery in Cursor
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
//Total number of images
int count = cursor.getCount();
//Create an array to store path to all the images
String[] arrPath = new String[count];
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
//Store the path of the image
arrPath[i]= cursor.getString(dataColumnIndex);
Log.i("PATH", arrPath[i]);
}
可能的解决方案是转到每个文件夹,然后检查.pdf是否存在,如果可以,则可以对该文件执行任何操作
public void Search_Dir(File dir) {
String pdfPattern = ".pdf";
File FileList[] = dir.listFiles();
if (FileList != null) {
for (int i = 0; i < FileList.length; i++) {
if (FileList[i].isDirectory()) {
Search_Dir(FileList[i]);
} else {
if (FileList[i].getName().endsWith(pdfPattern)){
//here you have that file.
}
}
}
}
}
和函数调用将是
Search_Dir(Environment.getExternalStorageDirectory());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句