簡體   English   中英

從 DownloadManager 下載的音頻文件未反映在 Android Q 上的 MediaStore 中

[英]Audio Files downloaded from DownloadManager does not reflecting in MediaStore on Android Q

我正在使用 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() 。還有其他選擇嗎?

下載完成后試試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM