【问题标题】:Is it possible to format secondary SD card in Android 10+?是否可以在 Android 10+ 中格式化辅助 SD 卡?
【发布时间】:2019-12-17 10:25:08
【问题描述】:

我正在编写一个应用程序,它使用通过 USB 集线器连接的专用 SD 卡(通常为 2-3 个)。布局如下:SD卡->USB集线器->手机。

是否有可能以编程方式 (Kotlin) 格式化 SD 卡 (exFAT)?

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    检查此代码

    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()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-16
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      相关资源
      最近更新 更多