1

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 GetContentUri(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 ?

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
user2791281
  • 149
  • 3
  • 12

1 Answers1

0

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.

Community
  • 1
  • 1
Amin
  • 1,034
  • 10
  • 17