Почему DownloadManager.Request "allowScanningByMediaScanner ()" не работает на Android Q? - PullRequest
0 голосов
/ 15 октября 2019

code ниже работает для любой Android версии ниже Q. Но когда я тестирую ее на Android Q, она не работает. Видео файл загружается и воспроизводится. Проблема с media scanner.

private void downloadVideo(String url, String videoPath) {
        try {
            File file = new File(videoPath);

            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url))
                    .setTitle(videoType.name() + " Video")
                    .setDescription("")
                    .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
                    .setDestinationUri(Uri.fromFile(file))
                    .setAllowedOverMetered(true)
                    .setAllowedOverRoaming(true);

            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, Uri.fromFile(file).getLastPathSegment());
            request.allowScanningByMediaScanner();

            DownloadManager downloadManager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
            downloadManager.enqueue(request);

            Toast.makeText(this, "Download started. Check notification bar for progress.", Toast.LENGTH_SHORT).show();
        } catch (Exception ex) {
            ex.printStackTrace();
            Toast.makeText(this, "Unable to download video", Toast.LENGTH_SHORT).show();
        }
    }
...