How to get list of videos on sd card

android

Solution

Query the `MediaStore` content provider

http://developer.android.com/reference/android/provider/MediaStore.html

An example could be

public static void printNamesToLogCat(Context context) {
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    String[] projection = { MediaStore.Video.VideoColumns.DATA };
    Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
    int vidsCount = 0;
    if (c != null) {
        vidsCount = c.getCount();
        while (c.moveToNext()) {
            Log.d("VIDEO", c.getString(0));
        }
        c.close();
    }
}

Problem

How can i get list of all videos on sd card? I just started learning android, and I want to create simple video player (I want to put videos from sd card in grid view). My guess is I should recursively scan all directories and filter video files, am I right? I could easily do it in java but maybe there is some dedicated tool in android?

Original source

Related problems