i am saving image in DCIM folder of internal storage by using below code:
public Uri saveBitmap(@NonNull final Context context, @NonNull final Bitmap bitmap,
@NonNull final Bitmap.CompressFormat format,
@NonNull final String mimeType,
@NonNull final String displayName) throws IOException {
final ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DISPLAY_NAME, displayName);
values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM);
final ContentResolver resolver = context.getContentResolver();
Uri uri = null;
try {
final Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
uri = resolver.insert(contentUri, values);
if (uri == null)
throw new IOException("Failed to create new MediaStore record.");
try (final OutputStream stream = resolver.openOutputStream(uri)) {
if (stream == null)
throw new IOException("Failed to open output stream.");
if (!bitmap.compress(format, 95, stream))
throw new IOException("Failed to save bitmap.");
}
return uri;
}
catch (IOException e) {
if (uri != null) {
// Don't leave an orphan entry in the MediaStore
resolver.delete(uri, null, null);
}
throw e;
}
}
now i want to save image in DCIM folder of external SDCARD but i don't know how to do it.
i know that i have to made changes in this line :
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM);
but Environment.DIRECTORY_DCIM
always return DCIM Folder of internal storage.
final Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
You only have to change that collection.MediaStore.Images.Media.getContentUri(name)
With name for example a value like 1CD3-23ED (or 1cd3-23ed) obtained fromMediaStore.getExternalVolumeNames(context);
– Haughtknow that i have to made changes in this line :
No. As that is all relative. – HaughtEnvironment.DIRECTORY_DCIM always return DCIM Folder of internal storage.
No. It's just equal to "DCIM". – Haught