0

I want to build a image slider that can shift images automatically with looping all images from phone's gallery. My android device is android 4.0.4. Can anyone help me out?

I have successfully built a image slider that can shift images automatically, but all the images are from the drawable resource that I created using Android Studio. I want the images come from gallery for better user interface.

My code is like this:

int images[] = {R.drawable.slide1, R.drawable.slide7, R.drawable.slide10};

It requires looping with array to do this, but I am a beginner of java.

Shashanth
  • 4,995
  • 7
  • 41
  • 51

1 Answers1

0

1) content provider may help. like

private ArrayList<String> getImages(Context context) {
        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 = context.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;
    }

loading images from gallery with content provider

also look to the file ways as those are also useful.

listing files

loading images from file path

Irfan Ul Haq
  • 1,065
  • 1
  • 11
  • 19