private void queryFiles(){
String[] projection = new String[] { MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.SIZE
};
Cursor cursor = getContentResolver().query(
Uri.parse("content://media/external/file"),
projection,
MediaStore.Files.FileColumns.DATA + " like ?",
new String[]{"%.txt"},
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int idindex = cursor
.getColumnIndex(MediaStore.Files.FileColumns._ID);
int dataindex = cursor
.getColumnIndex(MediaStore.Files.FileColumns.DATA);
int sizeindex = cursor
.getColumnIndex(MediaStore.Files.FileColumns.SIZE);
do {
String id = cursor.getString(idindex);
String path = cursor.getString(dataindex);
String size = cursor.getString(sizeindex);
docBean.setId(id);
docBean.setPath(path);
docBean.setSize(size);
int dot=path.lastIndexOf("/");
String name=path.substring(dot+1);
Log.e("test",name);
} while (cursor.moveToNext());
}
}
cursor.close();
}