Android3.0以上版本,快速获取TXT文件列表
作者:互联网
private void getEbookList(){
String[] columns = new String[] {
MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.DATA
};
Uri uri = MediaStore.Files.getContentUri("external");
String selection = "(" + MediaStore.Files.FileColumns.MIME_TYPE + "=='text/plain')";
Cursor c = getContentResolver().query(uri, columns, selection, null, MediaStore.Files.FileColumns.SIZE + " DESC");
if (c == null) return;
if (c.moveToFirst()) {
int dataIndex = c.getColumnIndex(MediaStore.Files.FileColumns.DATA);
int titleIndex = c.getColumnIndex(MediaStore.Files.FileColumns.TITLE);
do {
c.getString(titleIndex); // 获取文件名,不包含扩展名
c.getString(dataIndex); // 获取文件实际路径
} while (c.moveToNext()); // 循环获取文件
}
c.close();}
标签:Files,selection,String,列表,获取,FileColumns,TXT,Android3.0,MediaStore 来源: https://blog.51cto.com/u_15298588/3034047