I have a file at /sdcard/myfolder/filename.txt
I access this file in my source code as follows:
File fileMyTextFile = new File("/sdcard/myfolder/file.txt");
At one point I check to see if the file exists before opening it to read it's data:
try {
if (fileMyTextFile.exists()) {
...
}
} catch (FileNotFoundException e) {
Log.d("MyApp", "file not found");
e.printStackTrace();
}
I keep getting the FileNotFoundException when my code reaches this point. This same code works without any changes in my other phones which have a lower version of android so I think this has to be something to do with app permissions.
I have declared these in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
I also have
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
....
In MainActivity.java I have also done this:
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST );
How do I access my custom files in android 13?