Webview – obsługa nietypowych linków

Dodać podczas tworzenia obiektu WebViewClient:

				
					            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                // open the tel: link in the user calling app
                if (url.startsWith("tel:")) {
                    Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    activity.startActivity(tel);
                    return true;
                    
                // open the mailto link in the user mail app
                } else if (url.contains("mailto:")) {
                    view.getContext().startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                    return true;

                // open links to other websites in the user's internet browser
                } else if (!url.contains("yourwebsitedomain1") &&
                        !url.contains("yourwebsitedomain2")) {

                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    activity.startActivity(intent);
                    return true;

                } else {
                    view.loadUrl(url);
                    return true;
                }
            }
				
			

Zostaw komentarz