Android 6.0(API级别23)中的USB OTG存储如何在没有root的情况下访问文件? [英] How app can access files on USB OTG storages in Android 6.0 (API level 23) without root?
问题描述
当用户连接USB OTG存储时,它显示在系统存储菜单中,它可以通过内置的文件管理器访问。用户可以使用新的内置文件管理器来访问USB OTG外部存储器上的所有文件,而无需root权限。
当我将USB OTG存储连接到我的Android设备时,它装载在 / storage / A03E-1DF5
以及 / mnt / media_rw / A03E-1DF5
需要访问此文件夹。
我正在开发Android媒体播放器应用程序。
如何访问我的应用程序中的Android 6.0上的USB OTG存储文件,如没有root权限的内置文件管理器?
PS我已经在我的应用程序中使用 checkSelfPermission
和 requestPermissions
函数,我的应用程序已经有 android.permission .READ_EXTERNAL_STORAGE
和 android.permission.WRITE_EXTERNAL_STORAGE
(更多信息请参阅: https://goo.gl/i83BN2 ),但看起来像这些权限只影响内部存储(MicroSD),而对于USB OTG则没有这样的粒度许可。
解决方案
nofollow> USB媒体支持文档,存储访问框架似乎是唯一可用的机制:
$ b
在Android 6.0中,任何未采用的设备都被认为是可移植的。 […]第三方应用程序必须通过存储访问框架与便携式存储上的文件进行交互;由于隐私和安全原因,直接访问被明确阻止。
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.
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.
这篇关于Android 6.0(API级别23)中的USB OTG存储如何在没有root的情况下访问文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!