Android11中的音频MediaStore的bulkInsert解析器无法使用。
创始人
2024-09-30 18:00:03
0

在Android 11中,bulkInsert解析器似乎没有在音频MediaStore中工作。为了解决这个问题,您可以使用其他方法将音频文件插入MediaStore。

下面是一个带有代码示例的解决方案,可以将音频文件添加到MediaStore:

val resolver = context.contentResolver
val contentValues = ContentValues().apply {
    put(MediaStore.Audio.Media.DISPLAY_NAME, fileName)
    put(MediaStore.Audio.Media.TITLE, songTitle)
    put(MediaStore.Audio.Media.MIME_TYPE, "audio/mpeg")
    put(MediaStore.Audio.Media.RELATIVE_PATH, "Music/$albumName")
    put(MediaStore.Audio.Media.IS_PENDING, 1) // Add this to mark file as pending
}

// Insert the new audio file into MediaStore.
val newUri = resolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, contentValues)

newUri?.let {
    resolver.openFileDescriptor(newUri, "w", null)?.use { descriptor ->
        val outputStream = FileOutputStream(descriptor.fileDescriptor)
        outputStream.write(fileContent)
        outputStream.close()
    }

    contentValues.clear()
    contentValues.put(MediaStore.Audio.Media.IS_PENDING, 0) // Update this to mark file as not pending

    resolver.update(newUri, contentValues, null, null)
}

这段代码使用ContentValues对象为音频文件设置属性,并使用insert()方法将文件插入到MediaStore中。然后,使用openFileDescriptor()方法和FileOutputStream类将文件内容写入新文件中。最后,使用update()方法将文件标记为“非待处理文件”。

使用此代码,您应该可以成功将音频文件插入到MediaStore中。

相关内容

热门资讯

重大发现!aapoker破解侠... 重大发现!aapoker破解侠是真的吗,cloudpoker外挂,大神讲解(有挂神器)是由北京得aa...
必看攻略!wepoker怎么下... 必看攻略!wepoker怎么下载游戏,wepoker透视脚本免费下载,详细教程(有挂技巧);致您一封...
发现一款!德州局透视脚本,HH... 发现一款!德州局透视脚本,HH平台挂,扑克教程(有挂技巧)1、很好的工具软件,可以解锁游戏的ai质量...
推荐十款!aapoker真的假... 推荐十款!aapoker真的假的,aapoker透视脚本下载,wpk教程(有挂攻略)是一款可以让一直...
一起来讨论!wepoker有辅... 1、一起来讨论!wepoker有辅助功能吗,wepoker数据分析工具,规律教程(有挂方法)2、进入...
总算了解!wepoker公共底... 1、总算了解!wepoker公共底牌,aapoker发牌逻辑,教你教程(有挂攻略)。2、aapoke...
今日头条!wepoker挂,h... 今日头条!wepoker挂,hhpoker底牌透视脚本,可靠技巧(有挂技巧);亲真的是有正版授权,小...
1.9分钟了解!wepoker... 1.9分钟了解!wepoker破解器激活码,aapoker怎么开辅助器,大神讲解(有挂神器)科技教程...
我来教大家!wepoker游戏... 我来教大家!wepoker游戏的安装教程,德普之星透视软件免费入口官网,攻略教程(有挂神器)关于德普...
一分钟秒懂!pokemmo辅助... 一分钟秒懂!pokemmo辅助器手机版下载,智星德州插件怎么下载,2025新版(有挂技巧);人气非常...