Saving to SD card in KitKat

后端 未结 1 958
刺人心
刺人心 2021-01-17 03:11

I am working on an Android tablet application that is being used by law enforcement. I had the tablet backup all the data to an external SD card. I wanted to be able to re

1条回答
  •  再見小時候
    2021-01-17 03:36

    It worked fine

    Only for devices where /mnt/extSdCard existed and was writeable. This is outside the bounds of the Android SDK, and there is no guarantee that any device will honor that specific path. Perhaps you were in a controlled environment, with a single device model, where making this assumption was (relatively) safe.

    Is there a workaround?

    As 323go mentions in the comments, you are welcome to use getExternalFilesDirs() (note the plural). If there is more than one element in the resulting list, the second and subsequent entries will be for "secondary external storage" such as removable cards. You can read and write from this directory without any required permissions.

    There is also ContextCompat, which offers a getExternalFilesDirs() implementation that works all the way back to API Level 4. It will only ever return one value on devices running less than API Level 19, but it allows you to skip version checking yourself, as plenty of API Level 19+ devices will also only return one value (e.g., they do not have an SD card slot populated with a card).

    I recently wrote a series of blog posts attempting to clarify the storage situation. You may be particularly interested in the one on removable storage.

    0 讨论(0)
提交回复
热议问题