I am using Android Studio and a virtual device (Nexus 5 S on x86).
I am trying for tests purposes to read a binary file from external storage.
When I connect to the device with 'adb shell' to the device, I can find the file in /storage/emulated/0
In my test activity, I just put this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String filename = "basse-normandie.map";
final File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), filename);
Log.i("FileTests", "file is '"+file.getAbsolutePath()+"'");
Log.i("FileTests", "file exists: "+file.exists());
file.setReadable(true);
Log.i("FileTests", "app can read file: "+file.canRead());
}
and in the manifest I put
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
I guess WRITE_EXTERNAL_STORAGE is not useful though.
In the logcat window, I get this:
06-25 19:03:46.648 5107-5107/org.airforce_one.filetests I/FileTests: file is '/storage/emulated/0/basse-normandie.map'
file exists: true
app can read file: false
and I can't find what I'm doing wrong... Every page I've looked on the net tells me to give the permissions, but no other hints...