【发布时间】:2018-06-07 12:31:34
【问题描述】:
伙计们!
此代码在 Android Oreo 上不起作用(但在旧版本上没问题,我可以看到通知和 DownloadManager.ACTION_DOWNLOAD_COMPLETE 广播消息)。
科特林
testButton.setOnClickListener {
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val uri = Uri.parse("[url for a mp3 file]")
val request = DownloadManager.Request(uri)
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
request.setAllowedOverRoaming(false)
request.setTitle("Test mp3")
request.setDescription("Wow!")
request.setVisibleInDownloadsUi(true)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/GadgetSaint/" + "/" + "Sample" + ".mp3")
val reference = downloadManager.enqueue(request)
}
【问题讨论】:
-
嗨,你知道为什么会这样吗?
-
好像是模拟器相关的问题,我找到了解决方法:request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
-
太棒了!您应该将其发布为答案-我在这里发疯了,查看所有 api 差异,看看他们是否只是忘记记录更改
标签: android kotlin android-download-manager download-manager android-8.0-oreo