1

Hi I'm new to android,

I came from this thread and followed how to use the Viewpager How to do Gallery Images swap Left To right bydefault

It seems like I'm loading the images from drawable:

private int[] GalImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.three
};

How do I get the images from the phone's gallery instead?

Community
  • 1
  • 1
JRebo
  • 17
  • 1
  • 5
  • Similar...? http://stackoverflow.com/questions/11144783/how-to-access-an-image-from-the-phones-photo-gallery – Santosh May 04 '17 at 02:43
  • you need to [Read Images](http://stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android) and add them to your custom Adapter – Koorosh Ghorbani May 04 '17 at 03:39
  • I see, I'll read the other thread and Read Images as well (I have to learn a lot) thank you guys – JRebo May 04 '17 at 16:07

1 Answers1

0

following function get all image list from gallery

    private ArrayList<String> getAllShownImagesPath(Activity activity) {
        Uri uri;
        Cursor cursor;
        int column_index_data, column_index_folder_name;
        ArrayList<String> listOfAllImages = new ArrayList<String>();
        String absolutePathOfImage = null;
        uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

        String[] projection = { MediaColumns.DATA,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME };

        cursor = activity.getContentResolver().query(uri, projection, null,
                null, null);

        column_index_data = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
        column_index_folder_name = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
        while (cursor.moveToNext()) {
            absolutePathOfImage = cursor.getString(column_index_data);

            listOfAllImages.add(absolutePathOfImage);
        }
        return listOfAllImages;
    }
vishal
  • 542
  • 6
  • 12