I have a problem that I'm finding it hard to understand.
I am working on an app that should control the storage space of the device to be able to carry out its usual processes, in addition to it; the application must be able to identify if a physical SD card exists (inserted in the slot) and prioritize its use instead of the emulated external space.
I have read a lot and tried many examples and the result is the same, I detail it below:
To save a file to the SD (supposedly) I use the sentence
File file = new File(Environment.getExternalStorageDirectory(), name);
where name
is a String
with the name of the file. The file is created always in the emulated external space, it does not matter if you have an SD in the slot, you do not use it. According to this , that should be the way correct
The isExternalStorageEmulated()
method always returns true
and the isExternalStorageRemovable()
method always returns false
I am cured in health of the following:
String state = Environment.getExternalStorageState();// siempre es "mounted" con SD o no presente
if(Environment.MEDIA_MOUNTED.equals(state)) {
...
}
Even this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
In all the places I have consulted, these methods do their job, but I do not understand in my case because I can not achieve the result I want.
I have tested my app on the following devices:
The result has been the same. In particular, the questions to solve would be: