Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ContentResolver instead of FileOutputStream #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand Down Expand Up @@ -57,6 +58,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -434,18 +436,25 @@ public void onFinish() {

if (isSDCARDMounted()) {
String folderName = "PhotoEditorSDK";
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), folderName);
// String folderDirectory = Environment.DIRECTORY_PICTURES;
// Use Downloads Directory as I'm having issue in Pictures due to Android 11 Storage Update
String folderDirectory = Environment.DIRECTORY_DOWNLOADS;
File mediaStorageDir = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(folderDirectory)));
if (!mediaStorageDir.exists() && !mediaStorageDir.mkdirs()) {
Log.d("PhotoEditorSDK", "Failed to create directory");
}

String selectedOutputPath = mediaStorageDir.getPath() + File.separator + imageName;
returnIntent.putExtra("imagePath", selectedOutputPath);
Log.d("PhotoEditorSDK", "selected camera path " + selectedOutputPath);
File file = new File(selectedOutputPath);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DISPLAY_NAME, imageName);
values.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.RELATIVE_PATH, folderDirectory);
Uri uri = getContentResolver().insert(MediaStore.Files.getContentUri("external"), values);

try {
FileOutputStream out = new FileOutputStream(file);
OutputStream out = getContentResolver().openOutputStream(uri);
if (parentImageRelativeLayout != null) {
parentImageRelativeLayout.setDrawingCacheEnabled(true);

Expand All @@ -458,6 +467,7 @@ public void onFinish() {
out.close();

try {
File file = new File(selectedOutputPath);
ExifInterface exifDest = new ExifInterface(file.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(imageOrientation));
exifDest.saveAttributes();
Expand Down