android - 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();
}
});
解决方案
尝试通过删除来删除字体的预加载
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
Oreo 中的源Webview 不起作用
推荐阅读
- swift - 如何制作方形视频?
- c# - 从 Azure 云中 Windows Server 上运行的 Active Directory 获取用户
- javascript - 将几天的数组拆分为几个月
- javascript - Return observable from async function
- javascript - 如何更新在 JSX.Element 中创建的组件?
- python - 使用 pip 7.1.2 和 Python 3.5 完全无法安装任何包
- python - 使用 IMDB 数据集 get_word_index 错误进行文本分类,如何更改路径
- firebase-authentication - 我可以更改 Firebase Auth Rest API 的 ID 令牌到期时间吗?
- powershell - 递归列出目录并排除某些文件和子目录
- c - Contiki 中的头文件在哪里?