private void saveImage() {
if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
showLoading("Saving...");
filename = String.valueOf(System.currentTimeMillis()) + ".png";
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "/" + getResources().getString(R.string.app_name));
try {
if (!file.exists())
file.mkdir();
file.createNewFile();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mPhotoEditor.saveAsFile(file.getAbsolutePath() + "/" + filename, new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {
hideLoading();
showSnackbar("Image Saved Successfully");
MediaScannerConnection.scanFile(EditImageActivity.this, new String[]{file.toString()}, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
Log.e(".provider", " : " + getPackageName() + ".provider");
Log.e("filepath", " : " + imagePath);
if (imagePath != null && !imagePath.isEmpty()) {
File file1 = new File(imagePath);
Log.e("file1", " : " + file1);
if (file1 != null) {
Uri imageUri = FileProvider.getUriForFile(
EditImageActivity.this,
getPackageName() + ".fileprovider", //(use your app signature + ".provider" )
file1);
mPhotoEditorView.getSource().setImageURI(imageUri);
Log.e("imageUri", " : " + imageUri);
}
}
}
@Override
public void onFailure(@NonNull Exception exception) {
hideLoading();
showSnackbar("Failed to save Image");
}
});
} catch (IOException e) {
e.printStackTrace();
hideLoading();
showSnackbar(e.getMessage());
}
}