Question:
I currently have an application running on 100 cell phones with android 2.3 (established by the customer), but they are changing the cell phones to 4.4 and I use the sd card
to store and then display as a product listing.
The problem is in Android 4.4 I can't create folders inside the sd card
, I currently use the following code for checking and creating the folder.
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
file = new File(Environment.getExternalStorageDirectory() + File.separator + "imagem");
file.mkdirs();
if (file.isDirectory())
{
//metodos que fazem pesquisa de imagens omitidos
}
path returned by the above methods on Android 2.3:
/mnt/sdcard/image
path returned by the above methods in Android 4.4 it lists as "Created" but does not create:
/storage/emulated/0/image
I looked at the documentation and got no results, did you change the way to access between versions?
AndroidManifest.xml
is already allowed to read and write to the sdcard.
Answer:
Newer Smartphones may have more than one External Storage . In addition to the sdcard they have a built-in. The path returned by Environment.getExternalStorageDirectory()
refers to the primary external storage device, which in these cases is the internal one.
As of version 19 (Android 4.4) the Context class provides the getExternalFilesDirs() method that returns a File[]
with the paths to all application-specific directories, from all external storage devices.
The first path returned in the array is the same as the one returned by getExternalFilesDir() .
To obtain the paths where to store data related to the application, as mentioned in the documentation , the methods mentioned above must be used and not Environment.getExternalStorageDirectory()
.