相关疑难解决方法(0)

在Android上下载文件

我正在编写一个Android应用程序,并希望让我的用户能够共享它创建的文档文件.

理想情况下,我希望看到的是在某个地方的HTTP服务器上托管的文件,因此用户可以在Android手机上启动浏览器,浏览相关页面,然后将文件下载到手机上.然后我想让我的应用程序能够打开下载的文件.

我不确定这是否可能,但肯定会有兴趣听到任何了解这些事情的人.不幸的是,我似乎很难自己提出答案 - 就像Android SDK的其他部分一样,相关文档严重不足.

android download

6
推荐指数
1
解决办法
7700
查看次数

如何在Android上的WebView中读取Blob中的数据?

我有一个服务器在浏览器上创建一个对象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?任何帮助,将不胜感激.

android blob android-webview

6
推荐指数
2
解决办法
8083
查看次数

标签 统计

android ×2

android-webview ×1

blob ×1

download ×1