2

I use this logic that every internal link contains 'myurl' string so it should be open in WebView and other external link in default browser.

package com.package.webviewapp; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webView = (WebView) findViewById(R.id.webView); webView.setWebViewClient(new MyWebViewClient()); String url = "http://myurl.com"; webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(url); } } class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if(url.contains("myurl")){ // Could be cleverer and use a regex view.loadUrl(url); // Stay within this webview and load url return true; } else { return super.shouldOverrideUrlLoading(view, url); // Leave webview and use browser } } } 

but it is opening all links in WebView. as it is mentioned here Open link from Android Webview in normal browser as popup it should work.

4
  • what is not working? Commented May 12, 2015 at 8:17
  • @ChiragSavsani all links are opening in webview. Commented May 12, 2015 at 8:20
  • Have you used <meta-data> tag to differentiate between ur own url and other url. Commented May 12, 2015 at 8:26
  • @Rollno1 i am just a newbie in android development it is my first experience with android and java so don't how to try other logic. Commented May 12, 2015 at 8:30

1 Answer 1

1

When you want to load other url use below method , it will open in default browser

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link)); startActivity(myIntent); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.