2

在我的前端应用程序中,我想获取 WebView 上显示的图像 URL,以便将这些图像呈现为按钮视图。图片由后端提供,它们也嵌入了href。我的第一个假设如下 - 从How to get link-URL in Android WebView with HitTestResult for a linked image (and not the image-URL) with Longclick - 获取 URL:

WebView.HitTestResult result = ((WebView) webView).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();

        }
    }

但是,正如我在调试时看到的那样,它停留在第一个 if 语句中。如果有任何帮助,将不胜感激!

最好的

4

0 回答 0