700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android sd卡 读写文件系统 安卓10写入和读取sdcard文件

android sd卡 读写文件系统 安卓10写入和读取sdcard文件

时间:2022-04-04 04:47:20

相关推荐

android sd卡 读写文件系统 安卓10写入和读取sdcard文件

从target=29开始,要想读取sdcard中的文件,通过Environment.getExternalStoreage读取sdcard文件的方式已经行不通了。

当然,官方提供了一种缓解策略,在application的manifest中定义:`

android:maxSdkVersion="28" />`

复制代码

创建并且写入文件

写入文件需要用户点击确定,并且如果文件重名,会默认在后面加上(1)这种括号123等等

发送intent:

val initialUri = Uri.parse("file:///sdcard/Downloads/")

val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {

addCategory(Intent.CATEGORY_OPENABLE)

type = "application/text"

putExtra(Intent.EXTRA_TITLE, "hot_exchange_${DateTimeUtils.formatNow()}.json")

// Optionally, specify a URI for the directory that should be opened in

// the system file picker before your app creates the document.

putExtra(DocumentsContract.EXTRA_INITIAL_URI, initialUri)

}

startActivityForRe

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。