我有一个在浏览器上创建对象 blob 的服务器,我想在 Android 应用程序的 WebView 中下载它。我尝试将请求重定向到浏览器实例以及使用下载管理器来执行此操作,但它们似乎都不起作用(即使我在 Chrome 中打开同一页面,下载操作也可以在那里工作)。
我尝试了以下代码,它抛出错误:
Android.content.ActivityNotFoundException:找不到处理 Intent 的 Activity { act=android.intent.action.VIEW dat=blob:https%3A//111.111.111.111%3A8080/40b63131-63b1-4fa4-9451-c6297bbd111a"
Edit
Android.content.ActivityNotFoundException:找不到处理 Intent 的 Activity { act=android.intent.action.VIEW dat=blob:http://digitalinsensu.com/0f0d6127-a0f1-44c3-af85-72f648258d6d
Code:
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype,long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
这会抛出 java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs 错误:
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype,long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
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);
}
});
我应该如何下载 blob?任何帮助,将不胜感激。