load the URLs of pictures from the Gallery - Android Media

Android examples for Media:Picture

Description

load the URLs of pictures from the Gallery

Demo Code


//package com.java2s;
import java.util.ArrayList;
import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;

public class Main {
    /**//w w  w . j a  v  a 2s . co m
     * load the URLs of pictures from the Gallery
     * 
     * 
     * @return ArrayList<String> URLs of the pictures from the gallery
     */
    public static ArrayList<String> loadPicturesURLFromGallery(Context ctx) {

        ArrayList<String> galleryImageUrls = new ArrayList<String>();

        final String[] PICTURES_STORAGE_COLUMNS = { MediaStore.Images.Media.DATA };

        final String orderByDtaes = MediaStore.Images.Media.DATE_TAKEN
                + " DESC";

        Cursor imageCursor = ctx.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                PICTURES_STORAGE_COLUMNS, null, null, orderByDtaes);

        if (imageCursor.moveToFirst()) {

            for (imageCursor.moveToFirst(); !imageCursor.isAfterLast(); imageCursor
                    .moveToNext()) {
                int dataColumnIndex = imageCursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                galleryImageUrls.add("file://"
                        + imageCursor.getString(dataColumnIndex));
            }

        }

        return galleryImageUrls;
    }
}

Related Tutorials