Попробуйте, надеюсь, это сработает для вас
switch (requestCode) {
case 42:
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
InputStream inputStream = null;
try {
inputStream = getBaseContext().getContentResolver().openInputStream(uri);
Bitmap bm = BitmapFactory.decodeStream(inputStream);
int maxHeight = 1920;
int maxWidth = 1920;
float scale = Math.min(((float) maxHeight / bm.getWidth()), ((float) maxWidth / bm.getHeight()));
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
Bitmap bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
saveImageToInternalStorage(bitmap, getFileName(uri));
bm.recycle();
bitmap.recycle();
File file = new File(convertMediaUriToPath(uri)); // it will get the absolute path of your file from your URI
if (file.delete()) // it will delete your actual file from storage, but not from any holder you placed it.
//Make a Toast that file is successfully deleted
else
//Make a Toast that file is not deleted
finishActivity(42);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Способ получения Absolute PATH
public String convertMediaUriToPath(Uri uri) {
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
return path;
}
Надеюсь, что это сработает для вас :) Дайте мне знать, если это работает или нет.