应用程序如何在没有 root 的情况下访问 Android 6.0(API 级别 23)中 USB OTG 存储上的文件? [英] How app can access files on USB OTG storages in Android 6.0 (API level 23) without root?

查看:54
本文介绍了应用程序如何在没有 root 的情况下访问 Android 6.0(API 级别 23)中 USB OTG 存储上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 6.0 开发者预览版(API 级别 23)可以直接安装外部可移动 USB OTG 存储设备,无需任何其他应用程序(有关更多信息,请参阅:https://www.androidpolice.com/2015/05/28/android-m-feature-spotlight-external-storage-can-be-adopted-as-true-internal-storage-or-accessed-normally-with-no-additional-apps/).

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://www.androidpolice.com/2015/05/28/android-m-feature-spotlight-external-storage-can-be-adopted-as-true-internal-storage-or-accessed-normally-with-no-additional-apps/).

当用户连接 USB OTG 存储时,它会显示在系统存储菜单中,并且可以通过内置文件管理器访问.用户无需root权限即可使用新的内置文件管理器访问USB OTG外部存储上的所有文件.

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.

当我将 USB OTG 存储连接到我的 Android 设备时,它安装在 /storage/A03E-1DF5/mnt/media_rw/A03E-1DF5,但访问此文件夹需要 root 权限.

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.

我正在开发 Android 媒体播放器应用.

I'm working on Android media player app.

是否可以以及如何在我的应用程序中访问 Android 6.0 上 USB OTG 存储上的文件,例如没有 root 权限的内置文件管理器?

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?

附言我已经在我的应用程序中使用了 checkSelfPermissionrequestPermissions 函数,我的应用程序已经有 android.permission.READ_EXTERNAL_STORAGEandroid.permission.WRITE_EXTERNAL_STORAGE(更多信息请参见:https://www.androidpolice.com/2015/07/15/android-m-feature-spotlight-apps-now-需要您的权限来读取和写入到外部存储/),但看起来这些权限只影响内部存储(MicroSD),而对于 USB OTG 则没有这种细粒度的权限.

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://www.androidpolice.com/2015/07/15/android-m-feature-spotlight-apps-now-need-your-permission-to-read-and-write-to-external-storage/), but looks like these permissions only affects internal storages (MicroSD), and for USB OTG there is no such granular permission.

推荐答案

自 Android 6 起,根据 USB 媒体支持 文档,存储访问框架似乎是唯一可用的机制:

Since Android 6, according to the USB Media Support documentation, the Storage Access Framework seems to be the only available mecanism:

在 Android 6.0 中,任何未被采用的设备都被认为是便携式的.[…]第三方应用程序必须通过存储访问框架才能与便携式存储上的文件进行交互;出于隐私和安全原因,直接访问被明确阻止.

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.

这篇关于应用程序如何在没有 root 的情况下访问 Android 6.0(API 级别 23)中 USB OTG 存储上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆