How to open extarnal url in default browser and all internal links in WebView Android? -


i use logic every internal link contains 'myurl' string should open in webview , 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")){ // cleverer , use regex             view.loadurl(url); // stay within webview , load url             return true;         } else {             return super.shouldoverrideurlloading(view, url); // leave webview , use browser         }     } } 

but opening links in webview. mentioned here open link android webview in normal browser popup should work.

when want load other url use below method , open in default browser

intent myintent = new intent(intent.action_view, uri.parse(download_link)); startactivity(myintent); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -