我想将文件写入外部存储,而当我看着usableSpace
的{{1}}时,它说只有515.74MB。
这是目录的典型context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
大小吗?如果您需要更多的存储空间来写入数据,该怎么办?
usableSpace
在模拟器上进行测试时,不同存储目录的usableSpace如下
private fun getStorageDirectory(): File {
return if (isExternalStorageWritable()) {
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
} else {
context.filesDir
}
}
private fun getUsableSpace(): Long {
return getStorageDirectory()?.usableSpace ?: 0L
}
在Google Pixel XL上进行测试时,不同存储目录的usableSpace如下
DEBUG ~~ [context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).usableSpace 515739648] 515.74MB
DEBUG ~~ [context.getExternalFilesDir(null).usableSpace 515739648] 515.74MB
DEBUG ~~ [context.filesDir.usableSpace 515739648] 515.74MB
DEBUG ~~ [context.externalCacheDir.usableSpace 515735552] 515.74MB
DEBUG ~~ [context.cacheDir.usableSpace 515735552] 515.74MB
所以我想在真正的设备上您有更多的写空间。