get All Image from MediaStore - Android Media

Android examples for Media:Picture

Description

get All Image from MediaStore

Demo Code

/* //from  w  ww .  j  a v  a2  s.c o m
 * @Title: MediaStoreHelper.java
 * Created by liubingsr on 2012-6-19 ????6:17:57 
 * Copyright (c) 2012 Zhima Information Technology Co., Ltd. All rights reserved.
 */
//package com.java2s;
import java.util.ArrayList;
import android.content.ContentResolver;

import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class Main {
    public static final Uri IMAGE_URI = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    public static ArrayList<String> getAllImage(ContentResolver cr) {
        String[] projection = { MediaStore.Images.Media.DATA };
        String sortOrder = MediaStore.Images.Media._ID + " desc";
        Cursor cur = cr.query(IMAGE_URI, projection, null, null, sortOrder);
        ArrayList<String> pathNameList = new ArrayList<String>();
        if (cur != null) {
            pathNameList = new ArrayList<String>();
            while (cur.moveToNext()) {
                String fileName = cur.getString(0);
                pathNameList.add(fileName);
            }
            cur.close();
        }
        return pathNameList;
    }
}

Related Tutorials