服务器在获得控制权之前接到了下载电话
onDownloadRequested(String url,String userAgent,String contentDisposition,String mimetype,long contentLength)
,我的问题是,是否有可能通过Webview调用服务器以获取url + contentdisposition + mimeType等的详细信息?
@Override
public void onDownloadRequested(String url,long contentLength) {
/*Intent i = new Intent(Intent.actION_VIEW);
i.setData(Uri.parse(s));
startactivity(i);*/
downloadViaDownloadManager(url,userAgent,contentDisposition,mimetype);
}
和downloadViaDownloadManager()具有下载管理器的实现。
我已检查有关服务器呼叫的问题。
这是dowloadViaDownloadManager()方法。
private void downloadViaDownloadManager(String url,String mimetype) {
Uri uri;
try {
uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setMimeType(mimetype);
String cookies = CookieManager.getInstance().getcookie(url);
request.addRequestHeader("cookie",cookies);
request.addRequestHeader("User-Agent",userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url,mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,URLUtil.guessFileName(url,mimetype));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getapplicationContext(),R.string.download_in_progress,Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(mactivity,R.string.url_not_supported,Toast.LENGTH_SHORT).show();
}
}