如何获取存储在SD卡外部存储中的文件的列表(音乐,图片...),修改文件的内容并覆盖Android 5.0+中的旧文件。
What you want is not strictly possible.
The closest you are going to get is:
Use ACTION_OPEN_DOCUMENT_TREE
to get the user to choose a document tree. The user can choose whatever the user wants. It does not have to be removable storage — it could be external storage, Google Drive, etc.
Given the Uri
that you get back from the ACTION_OPEN_DOCUMENT_TREE
activity, wrap it in a DocumentFile
using fromTreeUri()
.
From there, use DocumentFile
a bit like you would use File
, using listFiles()
and isDirectory()
recursively to walk the document tree.
For whatever content you want to modify, use getUri()
on the DocumentFile
to get the Uri
for that piece of content, use openInputStream()
on a ContentResolver
to read in the content, and use openOutputStream()
on a ContentResolver
to write out your modified content.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.