I'm using API 29 (Android 10) on a Samsung device for testing.
I want to create a simple txt file.
This method is executed when clicking a button.
private void createFile() {
String path = getExternalFilesDir(null).toString();
path = path.substring(0, path.indexOf("/Android"));
Toast.makeText(getApplicationContext(), "Creating " + path + "/MyFiles/File.txt", Toast.LENGTH_LONG).show();
File file = new File(path + "/MyFiles/File.txt");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
But I get this error on the instruction file.createNewFile()
:
2019-12-13 00:54:18.945 26573-26573/com.... W/System.err: java.io.IOException: Permission denied
I think my AndroidManifest is ok
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com...">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application...
I've granted all the permissions in settings