Issues traversing through directory hierarchy with Android Storage Access Framework / DocumentProvider using MTP

I am using your code to go in sub folders with adding lines: Uri childrenUri; try { //for childs and sub child dirs childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri)); } catch (Exception e) { // for parent dir childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri)); }

How app can access files on USB OTG storages in Android 6.0 (API level 23) without root?

Since Android 6, according to the USB Media Support documentation, the Storage Access Framework seems to be the only available mecanism: In Android 6.0, any device that is not adopted is considered portable. […] Third-party apps must go through the Storage Access Framework to interact with files on portable storage; direct access is explicitly blocked … Read more

Android Open External Storage directory(sdcard) for storing file

I had been having the exact same problem! To get the internal SD card you can use String extStore = System.getenv(“EXTERNAL_STORAGE”); File f_exts = new File(extStore); To get the external SD card you can use String secStore = System.getenv(“SECONDARY_STORAGE”); File f_secs = new File(secStore); On running the code extStore = “/storage/emulated/legacy” secStore = “/storage/extSdCarcd” works … Read more

Universal way to write to external SD card on Android

Summary You can grant read/write access to external SD card on the different api levels (API23+ at run time). Since KitKat, permissions are not necessary if you use app-specific directories, required otherwise. Universal way: The history says that there is no universal way to write to external SD card but continues… This fact is demonstrated … Read more

READ_EXTERNAL_STORAGE permission for Android

You have two solutions for your problem. The quick one is to lower targetApi to 22 (build.gradle file). Second is to use new and wonderful ask-for-permission model: if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (shouldShowRequestPermissionRationale( Manifest.permission.READ_EXTERNAL_STORAGE)) { // Explain to the user why we need to read the contacts } … Read more

Accessing external storage in Android API 29

On Android 10 Environment.getExternalStorageDirectory() and Environment.getExternalStoragePublicDirectory() will return storage paths but paths are not readable or writable. For Android 10 you can continue to use paths provided by Environment.getExternalStorageDirectory() and Environment.getExternalStoragePublicDirectory() if you add android:requestLegacyExternalStorage=”true” to application tag in manifest file. At runtime your app can call Environment.isExternalStorageLegacy() to check if the request has been … Read more