Writing to external SD card in Android 5.0 and above
Android: EACCES (Permission denied) Writing files in Android system is easy with respect to internal storage, but when it comes to writing in external removable storage it may be a problem after android 4.4 release. Apart from android 6 permission we need to gain permission to write in external removable storage, as it can throw a EACCES (Permission denied) Error even if android.permission.WRITE_EXTERNAL_STORAGE is granted. So the following code will ensure that you can write in External media with the necessary permission apart from android.permission.WRITE_EXTERNAL_STORAGE. Call the following function to open the system dialog to gain access with external removable storage. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, 42); also the Activity Result Listener as follows: @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { ...