我正在使用DownloadManager下载音频文件
val token = getAccessToken()
val request = DownloadManager.Request(uri)
.addRequestHeader("Authorization", "OAuth $token")
.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, fileName)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.allowScanningByMediaScanner()
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadManager.enqueue(request)
,但下载的文件未反映在MediaStore中。我知道在Android 10中不建议使用allowScanningByMediaScanner()。有没有其他选择?
答案 0 :(得分:0)
下载完成后,请尝试以下操作:
val toBeScanned = arrayOf<String>(musicPath)
MediaScannerConnection.scanFile(
this, toBeScanned, null
) { path, uri -> println("SCAN COMPLETED: $path") }