Webview always redirects to twitter sign up url

288 views Asked by At

I am facing this strange issue with web view of android. I am trying to load this in my web view but it is always redirecting to this url.

Here is my the snippet of webview

    web=(WebView)findViewById(R.id.linkwebview);
            web.getSettings().setJavaScriptEnabled(true);
            web.getSettings().setPluginState(PluginState.ON);
            web.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
            web.getSettings().setBuiltInZoomControls(true);
            web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
            web.getSettings().setDomStorageEnabled(true);
web.setWebViewClient(new MyWebViewClient());
            web.loadUrl("https://www.facebook.com/sachintendulkar");

class MyWebViewClient extends WebViewClient {
        @Override
        // show the web page in webview but not in web browser
        public boolean shouldOverrideUrlLoading(WebView view, String url) {


            view.loadUrl(url);


                bck.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        if(web.canGoBack())
                        {
                        web.goBack();
                        }
                    }
                });

                forth.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        if(web.canGoForward())
                        {
                        web.goForward();
                        }


                    }
                });


            refresh.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    web.reload();

                }
            });



            return true;
        }

Not getting where the problem actually is.?

1

There are 1 answers

0
Harish Godara On BEST ANSWER

Change the user agent of webview like :

String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";// your_user_agent_setting
 mWebView.getSettings().setUserAgentString(newUA);

In your setting you have maintained Safari in last and Mozila in start of your user agent setting