【发布时间】:2017-12-23 05:54:13
【问题描述】:
过了很久,我才习惯了WebView。所以让我问一下我有什么相位问题。
-我在谷歌上找到了Blob URL,但我找不到解决方案或任何提示,所以我必须在这里发布问题。
-我在 android 端有 WebView 来加载网站。在他们的开按钮上"SAVE-AS" to download an image。
-现在当我在Google Chrome app 上尝试它时,它是working fine 并正确下载。
-现在与webview 在我的应用程序DownloadListener 中的情况相同
我得到了类似的 Blob URL
blob:http://-----cantshare-----.com/7e7452c8-62ca-4231-8640-0e9de715e073
所以下载管理员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");
【问题讨论】:
-
你有没有下载文件?
-
阅读 blob 运气好吗?
标签: android image webview download bloburls