WebView link click open default browser

Now I have an application that downloads a web view, and all clicks are stored in the application. What I would like to do is when a certain link is open in the application, for example http://www.google.com , which opens the default browser. If anyone has any ideas please let me know!

+78
android
Nov 19 '10 at 21:23
source share
5 answers

I had to do the same today, and I found a very useful answer to StackOverflow, which I want to share here if someone needs it.

Source (from sven )

webView.setWebViewClient(new WebViewClient(){ public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url != null && url.startsWith("http://")) { view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else { return false; } } }); 
+145
Jun 14 '11 at 13:01
source share
 WebView webview = (WebView) findViewById(R.id.webview); webview.loadUrl(http://www.playbuzz.org); 

you do not need to include this code //webview.setWebViewClient (new WebViewClient ()); instead you need to use the d code below

 webview.setWebViewClient(new WebViewClient(){ public boolean shouldOverrideUrlLoading(WebView view, String url) { String url2="http://www.playbuzz.org/"; // all links with in ur site will be open inside the webview //links that start ur domain example(http://www.example.com/) if (url != null && url.startsWith(url2)){ return false; } // all links that points outside the site will be open in a normal android browser else { view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } } }); 
+23
25 Sep '13 at 8:32
source share

you can use intent for this:

 Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("your Url")); startActivity(browserIntent); 
+11
Nov 20 '10 at 4:42
source share

You only need to add the following line

 yourWebViewName.setWebViewClient(new WebViewClient()); 

Check this for official documentation.

+5
Mar 09 '15 at 0:18
source share

You can use Intent for this:

 Uri uriUrl = Uri.parse("http://www.google.com/"); Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); startActivity(launchBrowser); 
+4
May 10 '12 at 6:44
source share



All Articles