I want to display all photos form my phone and display them in gridview using Picasso. The problem is I don't know how to implement this.
Currentyly im using this to query all phone photos:
Cursor cursor;
String[] columns = new String[] {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.TITLE,
MediaStore.Images.ImageColumns.DATA};
cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
columns, null, null, null);
int columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);
int columnPath = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
And MediaStore.Images.Thumbnails.getThumbnail to get thumbnail's bitmap to inject to ImageView.
How could I implement it using Picasso?
Pretty simple. Just use the Uri.withAppendedPath
to build the URI and then feed it to Picasso. The latter will internally use its MediaStoreRequestHandler
to fetch the right image.
// Use the cursor you've defined (correctly)
int columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);
Uri imageURI = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(columnIndex));
Picasso
.with(context)
.load(imageURI)
.fit()
.centerInside()
.into(imageView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With