我正在编写一个Android应用程序,并希望让我的用户能够共享它创建的文档文件.
理想情况下,我希望看到的是在某个地方的HTTP服务器上托管的文件,因此用户可以在Android手机上启动浏览器,浏览相关页面,然后将文件下载到手机上.然后我想让我的应用程序能够打开下载的文件.
我不确定这是否可能,但肯定会有兴趣听到任何了解这些事情的人.不幸的是,我似乎很难自己提出答案 - 就像Android SDK的其他部分一样,相关文档严重不足.
我有一个服务器在浏览器上创建一个对象blob,我想在Android应用程序的WebView中下载它.我尝试将请求重定向到浏览器实例以及使用下载管理器执行此操作,但它们似乎都不起作用(即使我在Chrome中打开相同的页面,下载操作也在那里工作).
我尝试了以下代码,它抛出错误:
Android.content.ActivityNotFoundException:找不到处理Intent的活动{act = android.intent.action.VIEW dat = blob:https%3A // 111.111.111.111%3A8080/40b63131-63b1-4fa4-9451-c6297bbd111a"
编辑
Android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = android.intent.action.VIEW dat = blob:http://digitalinsensu.com/0f0d6127-a0f1-44c3-af85-72f648258d6d
码:
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);
}
});
Run Code Online (Sandbox Code Playgroud)
这会抛出java.lang.IllegalArgumentException:只能下载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);
}
});
Run Code Online (Sandbox Code Playgroud)
我该如何下载blob?任何帮助,将不胜感激.