I was expecting the code below to save an image to my local sdcard but when I run the app and trigger the saveCanvasImage() method it's not doing so. When I look in the LogCat I can find a System.err entry. The text says:
java.io.FileNotFoundException: /mnt/sdcard/drawPic1.png: open failed: EACCES (permission denied)
I thought this would create a new png file and save it in the directory. I'm obviously wrong. What can I change here to make it work?
public void saveCanvasImage() {
Log.d("bitmap","strm");
tv.setDrawingCacheEnabled(true);
Bitmap bm = tv.getDrawingCache();
File fPath = Environment.getExternalStorageDirectory();
File f = null;
f = new File(fPath, "drawPic1.png");
try {
FileOutputStream strm = new FileOutputStream(f);
bm.compress(CompressFormat.PNG, 80, strm);
strm.close();
}
catch (IOException e){
e.printStackTrace();
}
}
Did you put permission ?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
are you sure you have added this permission to write to external storage
android.permission.WRITE_EXTERNAL_STORAGE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With