How to launch a web link from within my WebView in a registered app on Android? -


in android app, have webview. want every link click within webview launch registered app on device, if any, otherwise open in external browser. example, if user clicks on facebook page link within webview, should launch facebook app (if facebook registered on device handle facebook links). if no app registered, should launch external browser (i.e, should not load page in same webview).

currently (by default), webview loads link clicked within webview within itself.

i realize need override shouldoverrideurlloading intercept link clicks:

webview.setwebviewclient(new webviewclient() {     @override     public boolean shouldoverrideurlloading(webview view, string url) {         // should go here trigger registered app or fall external browser link clicks in webview?     } });  

i looked @ intent filters, seems inverse of requirement (intent filters seem way me register my android app handle web clicks elsewhere).

update 1:

i not looking intercept particular host name or scheme - want every link clicked in web view 'delegated' android, android decides whether launch registered app, pop choice user pick app open in, or open in web browser, depending on user settings.

specifically, if click on link https://www.facebook.com/blah should launch in facebook app , take me blah page there.

the fix involved handling shouldoverrideurlloading true, , if url isn't within own app, returning true. when true returned, launches registered app or app chooser dialog or browser, depending on configured context.

    mwebview.setwebviewclient(new webviewclient()     {         @override         public boolean shouldoverrideurlloading(webview view, string url) {             boolean islocalurl = false;             try {                 url givenurl = new url(url);                 string host = givenurl.gethost();                 if(host.contains("myapp.com"))                     islocalurl = true;              } catch (malformedurlexception e) {               }             if (islocalurl)                 return super.shouldoverrideurlloading(view, url);             else             {                 intent intent = new intent(intent.action_view, uri.parse(url));                 startactivity(intent);                 return true;             }         }     } 

i realized current status on android (i tested on miui 7 on xiaomi mi 4, based on android kitkat, forums indicate broadly true pre-marshmallow androids @ least) link facebook page in webview not open in facebook app. nor give user option open in facebook app. used work earlier, not work now. launches in browser if use above code. lot of misunderstanding happened because of this. works expected other sites (twitter, quora, etc.).


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -