I am developing my first app and I have to read a txt file from memory card. I cant seem to get the read permission for any of the directories or files in /storage. I am using FileBrowserActivity from https://github.com/vaal12/AndroidFileBrowser to get a GUI for file selection. I have tried from the GUI and just passing the path to the file but none of them work. Here is what I have:
InputStream is = null;
File dir = Environment.getExternalStorageDirectory();
File f_path = new File(filepath);//dir,
Log.i(TAGraph, "file exists: " + f_path.exists() + " isDirectory: " + f_path.isDirectory() + " read: " + f_path.canRead());
if(f_path.exists() && !f_path.isDirectory() && f_path.canRead()) {
Log.i(TAGraph, "file from user1");
is = new BufferedInputStream(new FileInputStream(f_path));
Log.i(TAGraph, "file from user2");
}
else{
is = getAssets().open("DATA.txt");
Log.i(TAGraph, "file from Assets 3");
}
From Logcat:
11-24 16:15:29.636 31337-31337/com.elcheapo.ashplot I/tagraph: on FILE try1. filepath: /storage/DATA.txt
11-24 16:15:29.643 31337-31337/com.elcheapo.ashplot I/tagraph: file exists: true isDirectory: false read: false
11-24 16:15:29.643 31337-31337/com.elcheapo.ashplot I/tagraph: file from Assets 3
AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
I have tried with only read, both read and write and with and without SdkVersion.
I can always get the file from assets just not from the storage. The file is there. I have tried testing on the emulator and on LG G5. I am getting the filepath from the mainActivity. I have checked and the path passes through fine.(Dont know if Activity to Activity permissions change)