I want to create a new file in external storage if that file doesn't exist already.
I've already read similar questions in SO and have WRITE_EXTERNAL_STORAGE
permission in my manifest.
Testing on GenyMotion emulator with android 5.1 and xperia t with android 4.3 the result is same and I get "open failed: EACCES (Permission denied)" on file.createNewFile()
. I checked in runtime and getExternalStorageState
functoin return value is "MOUNTED".
Note: If I create the file manually, my code works perfectly and reads the content meaning that accessing to external storage is OK.
I although write to external storage another place in my code using getExternalPublicStorage
for saving captured image and it works fine!
File f = Environment.getExternalStorageDirectory();
File config = new File(f, "poinila config" + ".txt");
if (!config.exists()) {
if (!config.createNewFile()) {
// toast that creating directory failed
} else {
writeDefaultIpPort();
}
}
Edit: path string is "/storage/sdcard0/poinila config.txt"