I am Using following code to convert bitmap Image to Uri
public static Uri getImageUri(Context context, Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
return Uri.parse(path);
}
Its working fine in Devices above from Marshmellow but not working in below versions
MediaStore.Images.Media.insertImage
Mentioned above code in the method is returning null in case of failure.I searched through the internet but could not get any rightful answer. Hoping for proper guidelines.
I am using karbon 5.1 (API 22)
MediaStore.Images.Media.insertImage is actually accessing external storage to save the image. Some important reminders which might be causing your app to fail:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.