android - 从 url 下载音频(文件)到 externalCache
问题描述
我有音频“网址”“https://my-server.com/555.mp3”
如何将其下载到“externalCacheDir”以便无需互联网即可轻松访问
我尝试使用 DownloadManager 但我认为有更好的方法来做到这一点
fun downloadAudio(url:String){
val request = DownloadManager.Request(url.toUri())
val externalCachPath = getApplication<Application>().externalCacheDir!!.absolutePath
val fileName = "${UUID.randomUUID()}.3gp"
request.setDestinationInExternalPublicDir(externalCachPath,fileName)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
request.setDescription("Download")
request.setTitle(fileName)
download(request)
return filename
}
解决方案
推荐阅读
- arrays - C - 迭代 numberOfProducts 变量不起作用
- c++ - 在 C++-17 中,如何在编译时检测模板化静态成员函数的存在
- git - Github 的主页?
- java - EJB 与执行相同功能的其他技术的主要区别?
- r - 对数据表对象使用 facet wrap
- python - 如何在乌龟中不回溯路径的情况下制作未填充的策略?
- discord.js - .setTimestamp 不适用于使用循环编辑的嵌入
- ruby-on-rails - Rails(5.2)中的防弹资产管道规范-如果资产pipie中缺少任何model.css或model.coffee,如何强制测试失败
- c# - Graph Api 读取电子邮件的权限
- python - python: tkinter 切换 svg 内容