Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso loading thumbnails of all phone photos

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?

like image 779
Dabler Avatar asked Feb 10 '15 13:02

Dabler


1 Answers

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);
like image 73
Sebastiano Avatar answered Nov 09 '22 12:11

Sebastiano