我希望获得除视频,图像和音频文件之外的所有类型的文档pdf,xml,doc。
显示名称,大小,日期和位置的列表。
ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Files.getContentUri("external");
// every column, although that is huge waste, you probably need
// BaseColumns.DATA (the path) only.
String[] projection = null;
// exclude media files, they would be here also.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
String[] selectionArgs = null; // there is no ? in selection so null here
String sortOrder = null; // unordered
Cursor allNonMediaFiles = cr.query(uri, projection, selection, selectionArgs, sortOrder);
我使用此代码从移动设备获取文件是否有效?以及如何获取文档详细信息,如uri,日期和名称。谢谢你。
答案 0 :(得分:0)
试试这个:
File path;
ArrayList<String> pdf_paths=new ArrayList<String>();
ArrayList<String> pdf_names=new ArrayList<String>();
path = new File(Environment.getExternalStorageDirectory() + "");
searchFolderRecursive1(path);
private static void searchFolderRecursive1(File folder)
{
if (file.isFile())
{
//.pdf files
if(file.getName().contains(".pdf"))
{
file.getPath();
pdf_names.add(file.getName());
pdf_paths.add(file.getPath());
Log.e("pdf_paths", ""+pdf_names);
}
else if(file.getName().contains(".doc"))
{
file.getPath();
pdf_names.add(file.getName());
pdf_paths.add(file.getPath());
}
}
}
答案 1 :(得分:-1)
String ext = FilenameUtils.getExtension(mediSore.getString(mediSore.getColumnIndex(MediaStore.Files.FileColumns.DATA))); if(ext.equals(“pdf”)|| ext.equals(“txt”)|| ext.equals(“docx”)|| ext.equals(“xlsx”)|| ext.equals( “CSV”)|| ext.equals( “ODS”)|| ext.equals( “ODT”) ){ Array.add( mediSore.getString(mediSore.getColumnIndex(MediaStore.Files.FileColumns.DATA))+“ - ”+ mediSore.getString(mediSore.getColumnIndex(MediaStore.Files.FileColumns.TITLE))+“---”+ mediSore.getString(mediSore.getColumnIndex(MediaStore.Files.FileColumns.DISPLAY_NAME)) );