user3667104
user3667104

Reputation: 37

WebView android (open browser)

I need to open webbview currunt URL in Browser when button is clicked.

Now have this code:

 WebView webview;
private WebView mWebView;
/**
  * Dichiariamo l'attributo di classe url in cui  
  * salviamo l'indirizzo web che aprirˆ la webview
  */
private String url = "http://www.google.com";

Have need code for open current url webview in browser.

Thanks

Upvotes: 0

Views: 152

Answers (2)

bhuvesh
bhuvesh

Reputation: 749

You can create mWebView instance field of type WebView and then assign it to your webview id from xml like this,

WebView mWebView = (WebView) findViewById(R.id.webView1);

and then load the url using loadUrl method,

        webView.loadUrl("your URL here");   

If you want to load this url in browser when button is clicked,

        Button button1;
        button1 = (Button) findViewById(R.id.myButton);
        button1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("your URL"));
                startActivity(browserIntent);

            }
        });

Upvotes: 2

alijandro
alijandro

Reputation: 12147

Try this

String url = "http://www.google.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);

Upvotes: 1

Related Questions