Get List of Photo Galleries on Android

Get list of photo galleries on Android

Groupings are defined by MediaStore.Images.Media.BUCKET_DISPLAY_NAME. Here is the sample code to list the images and log their bucket name and date_taken:

// which image properties are we querying
String[] projection = new String[] {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN
};

// content:// style URI for the "primary" external storage volume
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

// Make the query.
Cursor cur = managedQuery(images,
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
null // Ordering
);

Log.i("ListingImages"," query count=" + cur.getCount());

if (cur.moveToFirst()) {
String bucket;
String date;
int bucketColumn = cur.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME);

int dateColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATE_TAKEN);

do {
// Get the field values
bucket = cur.getString(bucketColumn);
date = cur.getString(dateColumn);

// Do something with the values.
Log.i("ListingImages", " bucket=" + bucket
+ " date_taken=" + date);
} while (cur.moveToNext());

}

List of gallery albums in Android

Try this:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
String[] projection = new String[] {"DISTINCT " + MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME};
Cursor cur = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
StringBuffer list = new StringBuffer();
while (cur.moveToNext()) {
list.append(cur.getString((cur.getColumnIndex(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME))) + "\n");
}
view.setText(list);
setContentView(view);
}

How to get all the image from gallery to my application using recyclerview?and how to set image in onbind holder for loding gallery images

You have to first get all images from gallery in you activity then have to set the list of images to RecyclerView

Use below method to get all all images-

    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;
}

Now set the This list of images to RecyclerView Adapter.

Take this RecyclerView Example as an reffrence to set all gallery images.

Loading all images & videos from gallery in the app activity & selecting some of them

hi I can understand your problem what you want is an image/Video picker library .its bad idea to build it on your own as a beginner so my recommendation would be to choose community build libraries which will make your job much easier

link of a few Image Picker libraries
https://android-arsenal.com/tag/157 you can google to find more libraries

follow the instruction from their Github page and try to implement them in your project it will be much easier

my recommendation would be to use this library https://github.com/Mindinventory/Lassi-Android
as this library provides both image and video to be picked



Related Topics



Leave a reply



Submit