下载管理器在Android Oreo中不工作

下载管理器在Android Oreo中不工作,android,cordova,android-download-manager,download-manager,Android,Cordova,Android Download Manager,Download Manager,我的是cordova混合应用程序。我已经安装了从服务器(url)下载pdf文件的插件。它在运行安卓7.0的设备上运行良好。当同一个应用程序安装在Oreo设备上时,什么都不会发生,过了一段时间,我看到“下载不成功”的消息。这可能是什么原因 我还升级了一款手机,它以前在那里工作,现在升级到了8.0并进行了测试。它失败了。所以当操作系统是Oreo时,这是不起作用的 private void startDownload(String message, CallbackContext callbackCo

我的是cordova混合应用程序。我已经安装了从服务器(url)下载pdf文件的插件。它在运行安卓7.0的设备上运行良好。当同一个应用程序安装在Oreo设备上时,什么都不会发生,过了一段时间,我看到“下载不成功”的消息。这可能是什么原因

我还升级了一款手机,它以前在那里工作,现在升级到了8.0并进行了测试。它失败了。所以当操作系统是Oreo时,这是不起作用的

private void startDownload(String message, CallbackContext callbackContext) {
        if (message != null && message.length() > 0) {
            String filename = message.substring(message.lastIndexOf("/")+1, message.length());
            try {
                filename = URLDecoder.decode(filename,"UTF-8");
            } catch (UnsupportedEncodingException e) {

                callbackContext.error("Error in converting filename");
            }
            android.app.DownloadManager downloadManager = (android.app.DownloadManager) cordova.getActivity().getApplicationContext().getSystemService(Context.DOWNLOAD_SERVICE);            
            Uri Download_Uri = Uri.parse(message);
            android.app.DownloadManager.Request request = new android.app.DownloadManager.Request(Download_Uri);
            //Restrict the types of networks over which this download may proceed.
            request.setAllowedNetworkTypes(android.app.DownloadManager.Request.NETWORK_WIFI | android.app.DownloadManager.Request.NETWORK_MOBILE);
            //Set whether this download may proceed over a roaming connection.
            request.setAllowedOverRoaming(false);
            //Set the title of this download, to be displayed in notifications (if enabled).
            request.setTitle(filename);
            //Set a description of this download, to be displayed in notifications (if enabled)
            request.setDescription("DataSync File Download.");
            //Set the local destination for the downloaded file to a path within the application's external files directory            
            request.setDestinationInExternalFilesDir(cordova.getActivity().getApplicationContext(), Environment.DIRECTORY_DOWNLOADS, filename);
            //Set visiblity after download is complete
            request.setNotificationVisibility(android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            long downloadReference = downloadManager.enqueue(request);
            callbackContext.success(message);
        } else {
            callbackContext.error("Expected one non-empty string argument.");
        }
    }

确保已在Menifest.xml文件中添加此权限


在模拟器或物理设备上尝试此操作?物理设备。所有的测试都是在物理设备上进行的
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 DownloadManager.Request request = new DownloadManager.Request(
            Uri.parse(url));

    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
    request.setDestinationInExternalPublicDir(
            Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(
                    url, contentDisposition, mimeType));
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    dm.enqueue(request);
    Toast.makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
            Toast.LENGTH_LONG).show();