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();
}
}