How to create new folder in sd card by using Storage Access Framework?

前端 未结 1 388
你的背包
你的背包 2021-01-14 11:29

I would like to know how to use \"Storage Access Framework\" to create new folder on SD card. If you give me the code it would be very good. I have already searched other qu

相关标签:
1条回答
  • 2021-01-14 12:11

    You cannot create "create new folder on SD card". You can create a new folder inside some other folder that the user chooses, but you cannot force the user to choose removable storage.

    To create a new folder inside of some other folder, this should work:

    1. Start an activity with startActivityForResult() on an ACTION_OPEN_DOCUMENT_TREE Intent, to allow the user to choose a folder. Include FLAG_DIR_SUPPORTS_CREATE to ensure that you can create something new in the folder.

    2. In onActivityResult(), wrap the Uri that you get in a DocumentFile, then call createDirectory() on it to create a new folder as a child of whatever the user chose.

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