如何修复Android Studio中绕过if语句的代码?

时间:2019-04-07 02:30:24

标签: java android

我正在尝试使用Jsoup在Android Studio中制作的WebView应用程序中获取当前用户的电子邮件,该Webview中使用的网站需要身份验证,因此通常不会有当前用户,以限制Jsoup在用户使用时查询WebView仍未通过身份验证,我实现了一条if语句,但以某种方式将其跳过

我的onCreate()中有此代码

        webView.setWebViewClient( new WebViewClientImpl(this){

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                webView_url=webView.getUrl();
                new MyTask().execute();
            }

        });

这是MyTask

private class MyTask extends AsyncTask<Void, Void, String> {

        @Override
        protected String doInBackground(Void... params) {

            if(webView_url != "http://gestioncapteursincendie.herokuapp.com/login" && webView_url!= "http://gestioncapteursincendie.herokuapp.com/"){
            Document doc = null;
            Element x = null;
            try {
                doc = Jsoup.connect(webView_url).get();
                System.out.println("Webview url 0 = " +webView_url);

                x = doc.getElementById("loggedin");
            } catch (IOException e) {
                e.printStackTrace();
            }

            System.out.println("Webview url= " +webView_url);
            System.out.println("loggedin= " + x);
            System.out.println("x val "+ x.val());
            return x.val();
            }
            return "NOTHING anymore";
        }


        @Override
        protected void onPostExecute(String result) {

            System.out.println("RESULT: "+result);
        }
    }

}

输出

04-07 03:27:29.188 18223-18581/com.gci.gestioncapteursincendie I/System.out: Webview url 0 = http://gestioncapteursincendie.herokuapp.com/login
04-07 03:27:29.188 18223-18581/com.gci.gestioncapteursincendie I/System.out: Webview url= http://gestioncapteursincendie.herokuapp.com/login
04-07 03:27:29.198 18223-18581/com.gci.gestioncapteursincendie I/System.out: loggedin= <input id="loggedin" name="loggedin" type="hidden" value="">
04-07 03:27:29.198 18223-18581/com.gci.gestioncapteursincendie I/System.out: x val 

0 个答案:

没有答案
相关问题