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);