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

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

Android 6.0 Developer Preview (API level 23) can natively mounts external removable USB OTG storages out-of-the-box without any additional apps (for more info please see: https://goo.gl/0UvsyN).

When user connects USB OTG storage, it shows up in the system storage menu and it is accessible with the built-in file manager. User can access all files on the USB OTG external storage using the new built-in file manager without root rights.

When I connect my USB OTG storage to my Android device, it mounts at /storage/A03E-1DF5 and also at /mnt/media_rw/A03E-1DF5, but root rights required to access this folder.

I'm working on Android media player app.

Is it possible and how to access files on USB OTG storages on Android 6.0 in my app like the built-in file manager without root rights?

P.S. I already use checkSelfPermission and requestPermissions functions in my app and my app already has android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE (for more info please see: https://goo.gl/i83BN2), but looks like these permissions only affects internal storages (MicroSD), and for USB OTG there is no such granular permission.

回答1:

In 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 for privacy and security reasons.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!