How to store a file on an SD card (external)

前端 未结 2 1598
深忆病人
深忆病人 2021-01-23 13:23

I want to store a file on the SD card using File. I already achieved to store a file in external storage (named internal storage in my file explorer app. This is NO

相关标签:
2条回答
  • 2021-01-23 13:31

    Using this may help you:

    An answer to Stack Overflow question How do I get the external storage's path?

    Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
    
    0 讨论(0)
  • 2021-01-23 13:36

    Ideally, you use the Storage Access Framework (e.g., ACTION_CREATE_DOCUMENT) and let the user choose where the user wants to put this content. The user may wish to put the content somewhere else. For example, the user may not have removable storage.

    Temporarily, you are welcome to use getExternalFilesDirs() and similar methods on Context. If these return 2+ elements, the second and subsequent ones are locations on removable storage. On Android 4.4+, your app can write to those locations without any particular permissions. Android Q is changing the rules here a lot, which is another reason to use the Storage Access Framework instead.

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