I’m trying to save a bitmap into the Pictures directory. Here’s the code
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(path, "test1.PNG");
try {
path.mkdirs();
OutputStream out = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
Log.w("ExternalStorage", "Error writing " + file, e);
}
But the execution got stuck at OutputStream out = new FileOutputStream(file);
I used the debugger and the full path returns mnt/sdcard/Pictures/test1.PNG, is mnt/ the culprit why I couldn’t get past OutputStream out = new FileOutputStream(file);? Because I can only see sdcard/ in my file directory.
thanks!
You can get and access the sdcard directory using this
Environment.getExternalStorageDirectory()as the mnt/sdcard or sdcard/ its an device dependent directory that how OS was access and use the external directory no need to worry for different device and different directory was return by this method.EDIT
For accessing external storage need permission and define in
androidmanifest.xmlfile as user permission