Picasso uploads thumbnails of all phone photos

I want to display all the photos from my phone and display them in a gridview using Picasso. The problem is that I do not know how to implement this.

I am currently using this to request all photos of the phone:

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 a bitmap thumbnail for injection into ImageView.

How can I implement it using Picasso?

+6
source share
1 answer

Pretty simple. Just use Uri.withAppendedPath to create the URI, and then submit it to Picasso. The latter will use its MediaStoreRequestHandler to get the correct 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); 
+4
source

Source: https://habr.com/ru/post/982268/


All Articles