I can not see files created from App android 6.0 in windows file browser

1

I have the following code:

File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/Inventario");
    if (!folder.exists()) {
        if (folder.mkdirs()) {
            Toast.makeText(this, "Carpeta Creada", Toast.LENGTH_SHORT).show();
        }

    }

the application generates the folder and is visible from the 'device' browser, but when I try to access from the computer it does not show me the folder. It is only visible after restarting the 'device'. the android version is 6.0

    
asked by fito120 11.04.2018 в 18:59
source

1 answer

-1

If you have files or folders created in the external storage directory, these can be displayed without any problem using a file browser or the same File Explorer of Android Studio .

Here the problem is that although you can view the files using File Explorer (File Explorer) , you can not programmatically read files or directories if you do not define the permission of WRITE_EXTERNAL_STORAGE , by defining this permission this implicit permission is READ_EXTERNAL_STORAGE .

For versions of the Android operating system prior to 6.0, it is sufficient to define the permission within AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

For later versions of Android 6.0, it is also important to require the permissions manually.

In this question you can see a method to require permission:

Error when displaying the external file directory in an AlertDialog in android 6.0 (READ_EXTERNAL_STORAGE / WRITE_EXTERNAL_STORAGE)

Important to mention that in some versions of the Android operating system there is no "Documents" directory to which Environment.DIRECTORY_DOCUMENTS relates, therefore it must first be created.

File folder = new File(Environment.getExternalStorageDirectory() + "/Documents");

    
answered by 11.04.2018 в 19:47