本文介绍了是否可以在Android 10+中格式化辅助SD卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个使用通过USB集线器连接的专用SD卡(通常为2-3个)的应用程序.布局如下:SD卡-> USB集线器->电话.
I'm writing an application that uses dedicated SD cards (usually 2-3) connected via a USB hub. The layout is as follows: SD cards -> USB hub -> Phone.
是否有可能以编程方式(Kotlin)格式化SD卡(exFAT)?
Is there any possibility to programmatically (Kotlin) format SD card (exFAT)?
推荐答案
检查此代码
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()
}
}
这篇关于是否可以在Android 10+中格式化辅助SD卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!