Пожалуйста, помогите мне решить эту проблему в моем коде, я хотел бы сохранить растровое изображение (newimage) на SD-карту в моем телефоне (Galaxy j7), но я получаю сообщение об ошибке (нет такого файла или каталога)
File filepath;
filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath()+"/save image");
dir.mkdirs();
File file = new File(dir,"myimage.png");
Toast.makeText(MainActivity.this,"image saved to SD",Toast.LENGTH_LONG).show();
try{
OutputStream stream ;
stream = new FileOutputStream(file);
newimage.compress(Bitmap.CompressFormat.PNG,100,stream);
stream.flush();
stream.close();
}catch (IOException e)
{
e.printStackTrace();
}
// Parse the saved image path to uri
Uri savedImageURI = Uri.parse(filepath.getAbsolutePath());
// Display the saved image to ImageView
// imagev.setImageURI(savedImageURI);
// Display saved image uri to TextView
tv_saved.setText("Image saved in external storage.\n" + savedImageURI);
сообщение об ошибке:
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/save image/myimage.png (No such file or directory)
Я добавил разрешение записи в manifest.xml следующим образом:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="21" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21"/>