Created
October 4, 2011 02:31
-
-
Save gunta/1260776 to your computer and use it in GitHub Desktop.
Androidで電話番号WebView
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
// http://以外のURLは新しいIntentを呼び出す | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
if( url.startsWith("http:") || url.startsWith("https:") ) { | |
return false; | |
} | |
// Otherwise allow the OS to handle it | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
startActivity( intent ); | |
return true; | |
} | |
// 或は | |
// tel://で始まるURLを新しいIntentで呼び出す | |
browser = (WebView) findViewById(R.id.webkit); | |
browser.setWebViewClient(new InternalWebViewClient()); | |
private class InternalWebViewClient extends WebViewClient { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
if (url.indexOf("tel:") > -1) { | |
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url))); | |
return true; | |
} else { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment