将网站中的图像保存在 WebView 中?

Save images from website inside a WebView?(将网站中的图像保存在 WebView 中?)
本文介绍了将网站中的图像保存在 WebView 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我四处搜索,大多数答案都与静态图像有关,即只有一张图像,并且 URL 已经预先定义.

I searched around and most of the answers relate to images that are static, i.e just the one image and the URL is already pre-defined.

我设置了一个 WebView 来将用户带到一个充满照片的网站.我希望用户能够按住图像并选择将其保存到手机.那可能吗?我当然不知道网址什么的,因为图片每天都在变化,而且数量很多.

I have a WebView set up to take users to a website full of photos. I want the user to be able to hold down on an image and get the option to save it to their phone. Is that possible? I of course don't know the URL or anything because the images change every day and there are a lot of them.

如果这有什么不同的话,网站上的图片都有自己的页面.它只是一个带有图像的网站.无需身份验证.就像在桌面上您可以右键单击并保存图像一样,我可以使用 WebView 来做到这一点吗?一定有办法,因为在默认浏览器中是可能的.

The images on the website all have their own page if that makes any difference. It's just a website with images. No authentication is required. Just like on a Desktop you can right click and save an image, can I do that with a WebView? There must be a way since it's possible in the default browser.

我一直在使用一个名为Reddit 很有趣"的应用程序,它具有此功能,从表面上看,它看起来像一个带有操作栏的简单 WebView,所以我认为这是可能的.

I've been using an app called 'Reddit is fun' that has this function and on the face of it, it looks like a simple WebView with action bar so I presume it's possible.

我将不胜感激.

推荐答案

是的,我想通了.

使用上下文菜单,我可以按住图像来拉取它的 URL.然后我可以让它使用 DownloadManager 启动下载.这一点是不言自明的,所以我将展示获取图像 URL 的代码.

Using a context menu I can hold down on an image to pull it's URL. Then I can have it initiate a download using DownloadManager. That bit is self-explanatory so I'll show the code to getting the image URL.

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // Confirm the view is a webview
    if (v instanceof WebView) {                
        WebView.HitTestResult result = ((WebView) v).getHitTestResult();

        if (result != null) {
            int type = result.getType();

            // Confirm type is an image
            if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
                String imageUrl = result.getExtra();
                Toast.makeText(this, imageUrl, Toast.LENGTH_LONG).show();

            }
        }
    }
}

这篇关于将网站中的图像保存在 WebView 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
appearance().setBackgroundImage Not Working On Custom Class(外观().setBackoundImage在自定义类上不起作用)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)