首页 > 解决方案 > Android:在 webview 中下载在 oreo 中不起作用,它在 Oreo 设备中强制关闭

问题描述

下载管理器代码不适用于 AndroidWebView的 Oreo 设备,但它适用于旧版本如果不是 Oreo 设备,它会启动“下载文件”并被下载,但如果是 Oreo,它会强制关闭(崩溃)

下面是我正在使用的代码(在片段中)

 webView.setDownloadListener(new DownloadListener() {
        @Override

        public void onDownloadStart(String url, String userAgent,
                                    String contentDisposition, String mimetype,
                                    long contentLength) {

            DownloadManager.Request request = new DownloadManager.Request(
                    Uri.parse(url));
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!

            DownloadManager dm = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);
            Toast.makeText(getActivity().getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
                    Toast.LENGTH_LONG).show();
        }
    });

标签: androidwebviewandroid-download-manager

解决方案


尝试通过删除来删除字体的预加载

<meta-data 
android:name="preloaded_fonts" 
android:resource="@array/preloaded_fonts" />  

Oreo 中的源Webview 不起作用


推荐阅读