I'm reading thumbnails from the device by querying the MediaStore, using MediaStore.Images.Thumbnails.getThumbnail()
. However, this has been deprecated in Android 10 (API 29), with a pointer to ContentResolver#loadThumbnail
: https://developer.android.com/reference/android/provider/MediaStore.Images.Thumbnails
However, I can't get this to work (in an emulated device running API 29). I've copied some JPEGs onto the emulated device, which end up in the Downloads folder. They show up fine in the Photos app. The following code gives me a FileNotFoundException. What does "No content provider" actually tell me?
try {
Size thumbSize = new Size(100, 100);
Uri thumbUri = Uri.fromFile(new File(imgPath));
// imgPath: /storage/emulated/0/Download/pexels-photo-323490.jpeg
// thumbUri: file:///storage/emulated/0/Download/pexels-photo-323490.jpeg
Bitmap thumbBitmap;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
thumbBitmap = mContext.getContentResolver().loadThumbnail(thumbUri, thumbSize, null);
} else {
thumbBitmap = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(),
imgId, MediaStore.Images.Thumbnails.MINI_KIND, null);
}
iconView.setImageBitmap(thumbBitmap);
} catch (Exception e) {
Log.e("err", e.toString());
}
Exception:
java.io.FileNotFoundException: No content provider: file:///storage/emulated/0/Download/pexels-photo-323490.jpeg
public class PhotoProvider extends ContentProvider
. My query method returns a cursor which contains, among other fields, the thumbnail "data" (i.e. path):String thumbData = cursor.getString(PhotoFragment.COL_THUMB_DATA);
– BonnettRecyclerViewCursorAdapter
class, which binds a row from the cursor to a view element in a RecyclerView (grid). – Bonnettfile:///storage/emulated/0/Download/pexels-photo-323490.jpeg
If you use an uri like that then no content provider is involved. And not yours either. Function .loadThumbnail() will never work with such an uri. – PhotonfromFile
method... – Bonnettint thumbColumn = cur.getColumnIndexOrThrow(MediaStore.Images.ImageColumns._ID); int _thumpId = cur.getInt(thumbColumn); Uri imageUri_t = imageUri_t = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,_thumpId);
– Mcneill