【问题标题】:how to make image downloadable in android app如何在android应用程序中使图像可下载
【发布时间】:2016-04-15 18:51:00
【问题描述】:

您好,我正在为我的网站使用在线免费服务构建一个应用程序。这个网站提供基于 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 手机中这项工作,当我单击下载此图像时..我的下载管理器将启动并将此图像保存到我的手机中..但是当我在其他手机上尝试时,这将不起作用..请帮助我,谢谢..

【问题讨论】:

  • 试试这个链接,一切都在这里:)stackoverflow.com/questions/33434532/…
  • 你会在这里找到它:) stackoverflow.com/questions/33434532/…
  • @LuckySharma 谢谢亲爱的,但我不知道 android 代码 .. 并且您提供的链接提供了 android 代码 .. 我不知道如何在 html 文件中使用 android 编码 ......任何其他简单的代码我可以在 html 文件中使用。
  • @LuckySharma 还有其他帮助吗?

标签: javascript android html


【解决方案1】:

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

因为它是一个混合应用程序,所以在你的 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

【讨论】:

  • 混合应用程序...通过 google play store 安装...它不是 m.mysite.com 之类的网站...它是用户通过 google 应用商店下载的应用程序...但我是使用在线免费应用程序构建服务构建它.. 在此您只需要使用 html 和 JavaScript ..
  • 为此,您需要在 android 级别的 webview 中添加一个监听器。 webview 是您在 android 中打开或呈现 html 页面的视图。
  • 亲爱的,再次感谢,但正如我所描述的,我不知道 android 编码,我使用的网站为我提供了 web 界面,应用程序构建器可以帮助我构建应用程序。就像拖放一样,我也可以插入 html 或 javascript 代码 .. 但我没有任何选项可以添加 android 代码 .. 我也不知道如何将 android 代码放入 html 文件中 ..
  • 亲爱的,但是如果您需要在您的 android 视图中打开或呈现任何 html 页面..您需要在 webview 中打开它,在 html 方面需要的更改与您编写的相同,代码需要在android端添加
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-26
  • 2013-09-02
  • 2011-07-25
  • 1970-01-01
  • 2012-04-03
  • 1970-01-01
相关资源
最近更新 更多