我将自己的网站转换为android webview应用。一切正常,但是当我尝试从我的网站下载任何文件时,文件正在以HTML格式下载。但是,当我尝试从PC或移动浏览器下载文件时,文件的下载格式正确。
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request myRequest = new DownloadManager.Request(Uri.parse(url));
myRequest.allowScanningByMediaScanner();
myRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager myManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Objects.requireNonNull(myManager).enqueue(myRequest);
Toast.makeText(MainActivity.this,"Download Started....", Toast.LENGTH_SHORT).show();
}
}