如何检测 WebView 是否已加载我的目标页面

huangapple go评论65阅读模式
英文:

How to detect if the webview already load my desired page

问题

以下是您要翻译的内容:

我想要获取 https://www1.kickassanime.rs 上的图片网址。

因此,我使用一些代码进行提取,我将我的代码放在 webview1 完成加载后。
这样,当 webview1 完成加载时,图片网址会自动加载到安卓上的 imageview 中。

但是这个网站 kickssanime,我不知道怎么说,可以查看一下这个网站,
您会首先看到一个空白页面,然后是他们的主页。看起来 webview 已经完成加载,但是他们的主页尚未呈现,请查看这个网站。

我想要在 webview 完成加载网站后自动获取第一张图片的网址。
我已经有代码从该网站获取图片网址,

(我的问题)
我想知道要添加什么代码,以便我的应用程序检测到 webview 是否已经加载了我想要的页面。

由于我的问题涉及逻辑问题,我不会添加我的代码。

英文:

I want to get the image url in https://www1.kickassanime.rs

So I use some code to extract it, I put my code on webview1 finished loading.
So that when the webview1 finished loading the image url from site automatically load to imageview on android.

But the site kickssanime, I dont know how to say it, please check the site,
You will see a blank page first and then their homepage. It seems the webview already finished loading but their homepage is not yet rendered, please check the site.

I want to get the first image url automatically
when webview finished loading the site.
I have already the code to grab the image url from the site,

(my question)
I want to know what code to add so that my app detect, if the webview already load my desired page.

I wont add my code since my question is logical problem

答案1

得分: 1

在您的活动/片段类中添加以下内容:

private boolean isPageLoaded = false;

webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public void onProgressChanged(WebView view, int progress) {
        if (progress == 100) {
            if (!isPageLoaded) {
                isPageLoaded = true;
            }
        }
    }
});

webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(Url);
英文:

Try this

in your activity/fragment class add

 private boolean isPageLoaded = false;

then

 webView.setWebChromeClient(new WebChromeClient() {
         
            @Override
            public void onProgressChanged(WebView view, int progress) {
                if (progress == 100) {
                    if(!isPageLoaded){
                        isPageLoaded=true;
                       
                    }

                }
            }


        });
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl(Url);

huangapple
  • 本文由 发表于 2020年10月22日 21:41:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64483558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定