当我们单击“提交”按钮时,将下载一些文件。如果将表单提交方法设置为“ GET”,则webview会调用onDownloadStart()方法来下载文件,但是如果您将表单提交方法设置为“ POST”, webview永远不会调用onDownloadStart()方法。
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
{
boolean isFlag = haveStoragePermission();
if(isFlag) {
System.out.println("Laxman:"+url+"\nuserAgent:"+userAgent+"\ncontentDisposition:"+contentDisposition+"\nmimetype:"+mimetype+"\ncontentLength:"+contentLength);
Toast.makeText(getApplicationContext(),"inside download"+mimetype,Toast.LENGTH_LONG).show();
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |
DownloadManager.Request.NETWORK_MOBILE);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
}
});
当前,当我正在使用GET方法文件正在下载,而使用POST方法文件却未下载时。 因此,请任何人告诉我是否可以使用POST方法下载文件。如果是,那么请帮助该怎么做。