As explained here:
http://www.doubleencore.com/2014/03/android-external-storage/
or here:
http://www.androidpolice.com/2014/02/17/external-blues-google-has-brought-big-changes-to-sd-cards-in-kitkat-and-even-samsung-may-be- implementing-them /
KitKat restricts writing to secondary external memory in a package-specific directory (although some developers have already found a workaround ...). With Samsung using the SD card as a secondary external storage and deploying its 4.4.2 update, this has become a serious problem for many applications.
My application has a save function that allows the user to select an arbitrary directory to save the file. I use Intents like org.openintents.action.PICK_DIRECTORY, com.estrongs.action.PICK_DIRECTORY or my built-in file explorer to select a directory. Of course, the user can freely choose any path on the SD card, but due to new restrictions with KitKat, the actual storage operation fails, if there is only one directory, my application does not have write access.
I need an alternative way to select a directory on KitKat so that the user does not receive an error message when he tries to save the SD card. This can be achieved by allowing them to select only the directories to which the application has write access.
I tried using Intent.ACTION_CREATE_DOCUMENT as follows:
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT) .addCategory(Intent.CATEGORY_OPENABLE) .setType(attachment.getContentType()) .putExtra(Intent.EXTRA_TITLE, attachment.getName()); startActivityForResult(intent, RequestCodes.MSG_CHOOSE_DIRECTORY);
This works fine, and I can write to the file that the user selected, but I only select specific directories. For example. for a pdf file, it will return the download directory (corresponding to Environment.DIRECTORY_DOWNLOADS), for jpg it will let me select the download directory and Google drive. However, it does not allow me to select other folders in the main external storage , and not in the package directory on the SD card (I tried different types of content, such as "* / *" or DocumentsContract.Document.MIME_TYPE_DIR, but to no avail).
So, I'm looking for a way so that the user can select a directory in the main external file system (as in the environment returned by Environment.getExternalStorageDirectory (), which is actually the internal storage), as well as all directories in which give me access to the secondary external memory to save the file in this directory. Regardless of whether the user selects a directory or file, the application will either use its own file name or the one that the user has selected.
Alternatively, knowing how certain applications have found a way to overcome new recording restrictions would of course be a viable option ;-). ES File Explorer, for example. can write any file to any directory on the SD card, as I can confirm from my own tests on unrooted S4 with sdcard.