经过很长一段时间,我使用了WebView。那么让我问一下我的阶段问题。
- 我有Blob URL
的谷歌,但我找到了解决方案或任何提示,所以我必须在这里发帖题。
- 我在Android端有WebView
来加载一个网站。在他们的按钮上"SAVE-AS" to download an image
。
- 当我在Google Chrome app
上尝试时,working
fine
并正确下载。
- 我的应用webview
与DownloadListener
相同的情况
我得到了类似
团块:http://-----cantshare-----.com/7e7452c8-62ca-4231-8640-0e9de715e073
所以downloadmanger download nothing
检查我的代码
webview = (WebView) findViewById(R.id.webview);
WebSettings settings = webview.getSettings();
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
final ProgressDialog progressBar = ProgressDialog.show(this, "WebView Example", "Loading...");
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Finished loading URL: " + url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e(TAG, "Error: " + description);
}
});
webview.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Uri webpage = Uri.parse(url);
if (!url.startsWith("http://") && !url.startsWith("https://")) {
webpage = Uri.parse("http://" + url);
}
DownloadManager.Request request = new DownloadManager.Request(
webpage);
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, contentDisposition,
mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(Main2Activity.this,
Environment.DIRECTORY_DOWNLOADS,".pdf");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File",
Toast.LENGTH_LONG).show();
}
});
Q1 - 任何人都可以提供建议如何从Blob URL下载文件?
Q2 - 必须更改服务器端?
Q3 - 以其他方式代替Downloadermanager?
我尝试了.pdf /.png/.jpeg
但no luck
;(
setDestinationInExternalFilesDir(Main2Activity.this,
Environment.DIRECTORY_DOWNLOADS,".pdf");