How to get all non media files in android 2.3 ?
ContentResolver cr = getApplicationContext().getContentResolver();
Uri uri = MediaStore.Files.getContentUri("external");
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + " = " + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
imagecursor = cr.query(uri, null, selection, null, null);
while (imagecursor.moveToNext()) {
count++;
}
From the above i am getting all non media files in Android 4.0 and above. But G etContentUri(external)
is not working in Android 2.3, its showing that its added in API level 11. Is there any alternative to get all non media files in Android 2.3 ?
As you said, MediaStore.Files
is only available for API 11+. So there isn't any method to use MediaStore
to do this. But you have two options to get the non-media files from a device's storage(s).
1. Iterating through all of the files in the storage: In my opinion this is not recommended at all. Because it takes about 15-30 seconds to iterate through all the files. But if you want to do this check here . Then you provide a simple condition to see if it is a non-media file.
2. Listing all the files once in a database and then get them: This is better than first method. For using it you can check this open-source application that exactly does that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.