Android write files to USB via OTG cable

后端 未结 2 366
闹比i
闹比i 2020-12-17 06:22

I\'ve been searching for many topics about android file writing, yet most of them wanted to write files to android internal storage. Others who wanted to write files on exte

2条回答
  •  借酒劲吻你
    2020-12-17 07:08

    From https://source.android.com/devices/storage/

    Starting in Android 4.4, ...

    The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions. Restricting writes in this way ensures the system can clean up files when applications are uninstalled.

    So, starting from Android 4.4 in devices with multiple external storages you will be able to write only on the primary external storage. Take into account that External Storage does not mean only "real external" devices. It is defined as follows (from the External Storage reference)

    External storage can be provided by physical media (such as an SD card), or by exposing a portion of internal storage through an emulation layer.

    Anyway there is a workaround to write to secondary external storage using the media content provider. Take a look at http://forum.xda-developers.com/showthread.php?t=2634840

    I have used it on a project of mine, but as the author says, it's far from the ideal solution, and it is not guaranteed to work on coming Android versions, so you must not let all your app to rely on this workaround.

提交回复
热议问题