Created
November 14, 2018 08:46
-
-
Save hwd6190128/83c83b7079620d087648ba827bbba621 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.setWebViewClient(new WebViewClient() { | |
@SuppressWarnings("deprecation") | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
return handlerUri(view, Uri.parse(url)); | |
} | |
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { | |
return handlerUri(view, request.getUrl()); | |
} | |
private boolean handlerUri(WebView view, final Uri uri) { | |
if (DEBUG) { | |
Logger.t(TAG).d("shouldOverrideUrlLoading: " + uri); | |
} | |
switch (uri.getScheme()) { | |
case "tel": | |
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(uri.toString()))); | |
return true; | |
case "mailto": | |
startActivity(new Intent(Intent.ACTION_SEND).setType("message/rfc822")); | |
return true; | |
default: | |
if (header != null && header.size() > 0) { | |
view.loadUrl(uri.toString(), header); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} | |
@Override | |
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { | |
super.onReceivedError(view, request, error); | |
isError = true; | |
} | |
@Override | |
public void onPageFinished(WebView view, String url) { | |
super.onPageFinished(view, url); | |
progressBar.setVisibility(View.GONE); | |
if (!isError) { | |
webView.setVisibility(View.VISIBLE); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you help me add this to my project?