Last active
January 27, 2016 10:27
-
-
Save andreban/9ba89eafd102bf527113 to your computer and use it in GitHub Desktop.
Handling Links on a WebView with Custom Tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebView webView = (WebView)findViewById(R.id.webview); | |
webView.setWebViewClient(new WebViewClient() { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
return true; | |
} | |
@Override | |
public void onLoadResource(WebView view, String url) { | |
if (url.startsWith("http://www.example.com")) { | |
//Handle Internal Link... | |
} else { | |
//Open Link in a Custo Tab | |
Uri uri = Uri.parse(url); | |
CustomTabsIntent.Builder intentBuilder = | |
new CustomTabsIntent.Builder(mCustomTabActivityHelper.getSession()); | |
CustomTabActivityHelper.openCustomTab( | |
this, intentBuilder.build(), uri, browserFallback, packageName); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment