Android 10 (Q) MediaScanner Bad performance after downloading a file via DownloadManager

285 Views Asked by At

After Downloading a mp3 file via android DownloadManager, Downloaded songs are not added quickly to the MediaStore database. Downloaded songs are not displayed in applications such as Google Music (Play Music), etc. And the phone needs to be restarted. Why?

DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(mp3Url));
request.allowScanningByMediaScanner(); // deprecated!
request.setTitle(title);
request.setDescription(description);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "song name.mp3");
//request.setDestinationUri(Uri.fromFile(new File(filePath))); // no longer access path on api 29 and higher
downloadManager.enqueue(request);
0

There are 0 best solutions below