android2013. 7. 3. 11:35

일단 현재 위치를 받기위해선  GeolocationPermissions.Callback를 implements 시킨다

( public class 클래스명 extends Activity implements GeolocationPermissions.Callback )


웹뷰 세팅 부분

WebSettings setting = web.getSettings();

setting.setJavaScriptEnabled(true); // 웹뷰에서 자바스크립트 실행 가능

web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

web.getSettings().setGeolocationEnabled(true);    // 현재위치 연결


String url = "연결 주소";

GeoClient geo = new GeoClient();

web.setWebChromeClient(geo);

String origin = ""; // how to get origin in correct format?

geo.onGeolocationPermissionsShowPrompt(origin, this); // obviously not how this is meant to be used but                 

  // expected usage not documented

web.loadUrl(url);




public void invoke(String origin, boolean allow, boolean remember) {


}


final class GeoClient extends WebChromeClient {


@Override

public void onGeolocationPermissionsShowPrompt(String origin,

Callback callback) {

// TODO Auto-generated method stub

super.onGeolocationPermissionsShowPrompt(origin, callback);

callback.invoke(origin, true, false);

}


}



출처 : http://stackoverflow.com/questions/2267513/using-navigator-geolocation-getcurrentposition-in-webview-on-android-2-0-phone

Posted by 광포한곰돌이
android2013. 7. 1. 09:11

웹뷰안에서 alert 를 하면 서버 host url이 나타난다.. 그걸 없애주기위해선 아래처럼 따로 구현을 해줘야함.



webView.setWebChromeClient(new ChromeClient() {

   

   @Override

   public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result){

      new AlertDialog.Builder(view.getContext())

         .setTitle("메세지")

         .setMessage(message)

         .setPositiveButton(android.R.string.ok,

               new AlertDialog.OnClickListener(){

                  public void onClick(DialogInterface dialog, int which) {

                     result.confirm();

                  }

               })

         .setCancelable(true)

         .create()

         .show();


      return true;

   };

   

   @Override

   public boolean onJsConfirm(WebView view, String url, String message, final android.webkit.JsResult result){

      new AlertDialog.Builder(view.getContext())

         .setTitle("메세지")

         .setMessage(message)

         .setPositiveButton(android.R.string.ok,

               new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {

                     result.confirm();

                  }

               })

         .setNegativeButton(android.R.string.cancel,

               new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {

                     result.cancel();

                  }

               })

         .create()

         .show();


      return true;

   };

   

  });

Posted by 광포한곰돌이
android2013. 7. 1. 09:03

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;

   }

  }

 };



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


전화걸기 권한

<uses-permission android:name="android.permission.CALL_PHONE" /> 



출처 :  http://titis.tistory.com/entry/%EC%9B%B9%EB%B7%B0WebView-%EC%95%88%EC%97%90%EC%84%9C-tel-%EB%B0%8F-sms-mailTo-%ED%83%9C%EA%B7%B8-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

Posted by 광포한곰돌이