如何在Android应用程序中下载图像

时间:2016-04-15 10:14:19

标签: javascript android html

您好我正在为我的网站使用在线免费服务构建应用程序。这个网站提供基于HTML的应用程序构建服务..我知道HTML JavaScript,但不知道Android编码。所以我需要帮助。我想允许用户下载图像(我们的设计)当用户点击下载按钮图像将保存在移动用户。可以请一些帮助我提供我将在我的html文件中使用的任何HTML或Java代码..我希望你理解我的问题..这里我尝试

<a class="WebKitTitle" href="imgurl.com/image.png" data-layout-editable="link" download=""><span data-layout-editable="text">Download This Image</span></a>

在mi3移动这项工作,当我点击下载这个图像..我的下载管理器将启动并将此图像保存到我的手机..但当我在其他手机上尝试这将无法正常工作..请帮助我谢谢..

1 个答案:

答案 0 :(得分:0)

您只是为浏览器或任何混合应用创建网站 ?

因为它是一个混合应用程序,所以在您的webview中添加一个列表器

webView.setDownloadListener(new DownloadListener()
  {
   public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
   {
    //for downloading directly through download manager
    Request request = new 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);
   }
  });

参考:http://technoranch.blogspot.in/2014/09/downloading-file-from-android-webview.html

相关问题