I’m attempting to write some text to an external file, on DragonBoard running Android. My hope would be to write the file onto the empty SD card that is mounted in the SD card slot on the DragonBoard. I’ve checked and the external storage is mounted - this method returns true:
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
But the following code always gets false from the canWrite() method:
File fileRoot = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_DOCUMENTS), "MyAppLogs");
if (fileRoot.canWrite()) {
// do something here
}
The path returned for fileRoot is "/storage/emulated/0/Documents/MyAppLogs. If I skip the canWrite() check and execute these lines:
File LogFile = new File(fileRoot, “MyAppLog.txt”);
FileWriter LogWriter = new FileWriter(LogFile, append);
then the second of these throws a “No such file or directory” exception.
Does anyone have any insights into a) why this is failing? and b) how to get the file written onto the SD card? Thanks in advance.