/**
     * 根据文件后缀名获得对应的MIME类型。
     * @param filePath
     */
    fun getMimeType(filePath: String?): String? {
        val mmr = MediaMetadataRetriever()
        var mime: String? = "text/plain"
        if (filePath != null) {
            mime = try {
                mmr.setDataSource(filePath)
                mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE)
            } catch (e: IllegalStateException) {
                return mime
            } catch (e: IllegalArgumentException) {
                return mime
            } catch (e: RuntimeException) {
                return mime
            }
        }
        return mime
    }
  val dest = KpadApplication.instance.getExternalFilesDir(null)!!.toString()+"/log.zip"
val result = getMimeType(dest)

 

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐