从DownloadManager下载的音频文件未反映在Android Q的MediaStore中

问题描述 投票:0回答:1

我正在使用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()。是否有其他选择?

android mediastore android-10.0
1个回答
0
投票

下载完成后尝试:

val toBeScanned = arrayOf<String>(musicPath) MediaScannerConnection.scanFile( this, toBeScanned, null ) { path, uri -> println("SCAN COMPLETED: $path") }

© www.soinside.com 2019 - 2024. All rights reserved.