Reputation: 200
Does below code need WRITE_EXTERNAL_STORAGE Permission? I mean does file.mkdirs(); need WRITE_EXTERNAL_STORAGE to write file
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH);
filename = sdf.format(new Date());
try {
String path = ctx.getApplicationContext().getFilesDir().getPath();
OutputStream fOut = null;
File file = new File(path, "thinkly");
if (!file.exists()) {
file.mkdirs();
}
File file2 = new File(file, filename + ".jpg");
fOut = new FileOutputStream(file2);
capturedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fOut);
fOut.flush();
fOut.close();
return file2.getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
return "";
}
Upvotes: 0
Views: 350
Reputation: 1649
All Android devices have two file storage options: internal storage and external storage.
internal storage:
External storage:
These are the common file access functions in Android, so you can know what needs permission and what doesn't:
In conclusion
In your code, you use the getFilesDir() method - so you do not need to ask for permission.
extrad:
External storage permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Upvotes: 2