I have tried this link It's explained there must keep Write External Storage permission must outside the application tag. I have already kept it outside.
I am putting my code here :
cvMain.setDrawingCacheEnabled(true);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "DEMO_" + timeStamp;
String path = createWorkingDirectory().getAbsolutePath() + "/" + imageFileName + ".jpg";
File fileTemp = new File(path);
if (!fileTemp.exists()) {
try {
fileTemp.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Bitmap b = cvMain.getDrawingCache();
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(fileTemp);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
b.compress(Bitmap.CompressFormat.JPEG, 95, fileOutputStream);
try {
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
cvMain.setDrawingCacheEnabled(false);
createWorkingDirectory() method :
private File createWorkingDirectory() {
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "demo");
if (!directory.exists()) {
directory.mkdirs();
}
return directory;
}
I am getting this error at specific createNewFile() method call time. I have been kept Write permission inside manifest and runtime applied, even though getting this error. What is the issue I could not understand? Please help me in this. Thank you.