我从服务器下载文件的代码在api级别28及以下工作正常,但在api级别29上不工作。
private fun downloadV(url: String) {
val fileName = System.currentTimeMillis().toString() + ".mp4"
val downloaduri = Uri.parse(url)
val request = DownloadManager.Request(downloaduri)
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
request.setAllowedOverRoaming(false)
request.setTitle(fileName)
request.setDescription(fileName)
request.setDestinationInExternalPublicDir("/XYZ", fileName)
request.allowScanningByMediaScanner()
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
downloadManager?.enqueue(request)
}
2条答案
按热度按时间ryhaxcpt1#
检查此文档一次https://developer.android.com/training/data-storage/shared/documents-files#grant-访问目录
或者尝试授予存储的运行时权限
ss2ws0br2#
将此行添加到应用程序标记中的清单