본문 바로가기

Develop/Android SDK

안드로이드 웹뷰(WebView) 안에서 tel 및 sms , mailTo 태그 사용하기


private class MyWebClient extends WebViewClient {
  public boolean shouldOverrideUrlLoading(WebView view, String overrideUrl) {
   if(overrideUrl.startsWith("http://")){
    return false;
   }
   else {
    boolean override = false;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(overrideUrl));
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
    if (overrideUrl.startsWith("sms:")) {
     Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse(overrideUrl));
     startActivity(i);
     return true;
    }
    if (overrideUrl.startsWith("tel:")) {
     Intent i = new Intent(Intent.ACTION_CALL, Uri.parse(overrideUrl));
     startActivity(i);
     return true;
    }
    if (overrideUrl.startsWith("mailto:")) {
     Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse(overrideUrl));
     startActivity(i);
     return true;
    }
    try{
     startActivity(intent);
     override = true;
    }
    catch(ActivityNotFoundException ex) {}
    return override;
   }
  }
 };


하나씩 다 지정 해줘야 함.. 물론 권한도 포함해서요~;)