[英]Is it possible to format secondary SD card in Android 10+?
I'm writing an application that uses dedicated SD cards (usually 2-3) connected via a USB hub.我正在编写一个应用程序,它使用通过 USB 集线器连接的专用 SD 卡(通常是 2-3 个)。 The layout is as follows: SD cards -> USB hub -> Phone.
布局如下:SD卡->USB集线器->手机。
Is there any possibility to programmatically (Kotlin) format SD card (exFAT)?是否有可能以编程方式(Kotlin)格式化 SD 卡(exFAT)?
Check this Code检查此代码
fun wipingSdcard() {
val deleteMatchingFile = File(Environment
.getExternalStorageDirectory().toString())
try {
val filenames = deleteMatchingFile.listFiles()
if (filenames != null && filenames!!.size > 0) {
for (tempFile in filenames!!) {
if (tempFile.isDirectory()) {
wipeDirectory(tempFile.toString())
tempFile.delete()
} else {
tempFile.delete()
}
}
} else {
deleteMatchingFile.delete()
}
} catch (e: Exception) {
e.printStackTrace()
}
}
private fun wipeDirectory(name: String) {
val directoryFile = File(name)
val filenames = directoryFile.listFiles()
if (filenames != null && filenames!!.size > 0) {
for (tempFile in filenames!!) {
if (tempFile.isDirectory()) {
wipeDirectory(tempFile.toString())
tempFile.delete()
} else {
tempFile.delete()
}
}
} else {
directoryFile.delete()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.