How to access SDCARD on Android 4.4 (API 19)

5

I currently have an application running on 100 phones with android 2.3 (set by the client), but they are switching phones to 4.4 and I use sd card to store and then display as a product listing.

The problem is in Android 4.4 I can not create folders within 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 in 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 , has the form of access changed between versions?

AndroidManifest.xml is already allowed to read and write to sdcard.

    
asked by anonymous 19.06.2015 / 19:22

1 answer

5

Newer Smartphones may have more than one External Storage . In addition to the sdcard have an internal. The path returned by Environment.getExternalStorageDirectory() refers to the primary external storage device which in these cases is the internal.

As of version 19 (Android 4.4), the Context class provides the getExternalFilesDirs () that returns a File[] with the paths for all application-specific directories of all external storage devices.

The first path returned in the array is the same as the one returned by getExternalFilesDir () .

For the paths to save application-related data, as referred to in documentation , the above methods should be used instead of Environment.getExternalStorageDirectory() .

    
20.06.2015 / 16:06