-1
如---- [doc.docx.xls.xlsx.ppt.pptx.pdf],就像下面的代碼一樣。但查詢結果只有pdf.doc.xls,而不是其他人,我很困惑。我找了很多的答案是不是我想要的查找辦公文件
private void doSearch() {
String[] projection = new String[]{
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.MIME_TYPE};
String selection = MediaStore.Files.FileColumns.MIME_TYPE + " = ? "
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? "
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? "
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? "
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? "
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? "
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? ";
String[] selectionArgs = new String[]{
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/msword",
"application/pdf",
"application/vnd.ms-excel"};
Cursor cursor = getContentResolver().query(MediaStore.Files.getContentUri("external"),
projection,
selection,
selectionArgs,
MediaStore.Files.FileColumns.DATE_MODIFIED + " desc");
String fileName;
String filePath;
while (cursor.moveToNext()) {
String type = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.MIME_TYPE));
fileName = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.TITLE));
filePath = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
Log.e("ryze_text", fileName + " -- " + type + "--" + filePath);//Here is the result
}
cursor.close();
cursor = null;
}
返回**所有**文件,不只是列出的文件 –
是的,現在我只能過濾結果中的後綴,獲取我想要的文件 –