Я не могу сохранить файл изображения даже после запроса разрешения. Я добавил разрешение в файл манифеста следующим образом:
permission.WRITE_EXTERNAL_STORAGE
Но я продолжаю видеть эту ошибку:
В доступе отказано
Вот соответствующий код:
@SuppressLint("MissingPermission")
private void saveImage() {
if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
showLoading("Saving...");
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + ""
+ System.currentTimeMillis() + ".png");
try {
file.createNewFile();
SaveSettings saveSettings = new SaveSettings.Builder()
.setClearViewsEnabled(true)
.setTransparencyEnabled(true)
.build();
mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {
hideLoading();
showSnackbar("Image Saved Successfully");
mSaveImageUri = Uri.fromFile(new File(imagePath));
mPhotoEditorView.getSource().setImageURI(mSaveImageUri);
}
@Override
public void onFailure(@NonNull Exception exception) {
hideLoading();
showSnackbar("Failed to save Image");
}
});
} catch (IOException e) {
e.printStackTrace();
hideLoading();
showSnackbar(e.getMessage());
}
}
}
А вот и журнал ошибок:
D/ViewRootImpl@faa5b66[EditImageActivity]: setView = com.android.internal.policy.DecorView@63d69b7 TM=true MM=false
W/System.err: java.io.IOException: Permission denied
W/System.err: at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)