Open browser in webView

-1

I have developed an app with a WebView in which a login page is displayed. However, as the login is no way to know which will be the next page to show, so it opens the browser outside the app. Would there be any chance that this new page could be opened in the webView itself?

public class MainActivity extends AppCompatActivity  {

    private TextView texto;
         private WebView web;
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);

             web=(WebView)findViewById(R.id.webV);

             //Habilitar JavaScript
             web.getSettings().setJavaScriptEnabled(true);
             web.loadUrl("https://www.launcher/");
         }
    
asked by pepito 27.06.2017 в 08:13
source

1 answer

3

In onCreate add the client to manage that the url and the control can be overwritten in case they sail backwards.

web.loadUrl("https://www.launcher/");

    web.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {

                            view.loadUrl(url);

                        return true;
    //                return super.shouldOverrideUrlLoading(view, url);
                    }

     web.setOnKeyListener(new View.OnKeyListener() {
                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        if (event.getAction() == KeyEvent.ACTION_DOWN) {
                            switch (keyCode) {
                                case KeyEvent.KEYCODE_BACK:
                                    if (web.canGoBack()) {
                                        web.goBack();
                                        return true;
                                    }
                                    break;
                            }
                        }

                        return false;
                    }
                });

I hope this works for you.

    
answered by 27.06.2017 / 09:56
source