Android WebView 下载不起作用 [英] Android WebView download not working

查看:61
本文介绍了Android WebView 下载不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含 html 表单页面的 web 视图,并且在提交表单时(使用 post 方法)它应该下载文件.

I have created one web view having page containing html form and on submitting form (with post method) it should download the file.

我已经实现了 webview 下载监听器,所以我可以处理下载.

I have implemented webview download listener so i can handle downloads.

@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition,
                            String mimetype, long contentLength) {
    DownloadManager.Request request = new DownloadManager.Request(
            Uri.parse(url));
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "DownloadFile.pdf");
    DownloadManager dm = (DownloadManager) getContext().getSystemService(Activity.DOWNLOAD_SERVICE);
    dm.enqueue(request);
}

现在的问题是,如果我在页面中的 HTML FORM 中使用 post 方法,则下载不起作用(如果我使用 GET 方法,它可以工作)

Now problem is, If i use post method in HTML FORM in page, download not working(it is working if i use GET method)

在 chrome 移动应用程序中,它适用于 post 方法,但不适用于 android web 视图.

in chrome mobile app it's works with post method, but it is not working in android web view.

推荐答案

遗憾的是 DownloadManager 不支持 POST 方法.请在39491780.

Unfortunately DownloadManager doesn't support POST method. Please find the corresponding issues 3949 and 1780.

您将不得不使用其他方式在您的应用程序中下载文件.

You will have to use alternative means to download the file in your application.

这篇关于Android WebView 下载不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆