11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidのWebViewでgeoloactionを使用する

Posted at

###位置情報取得用のパーミッションを追加

 <!-- 位置情報取得 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

###WebViewClient,WebChromeClientの設定

import android.webkit.GeolocationPermissions.Callback;

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setConsentView(R.layout.main);
    webView = (WebView)findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrLoading(WebView view, String url){
            return false;
        }
    });
    webView.setWebChromeClient(new WebChromeClient(){
        @Override
        public void onGeolocationPermissionsShowPrompt(String origin, Callback callback){
            callback.invoke(origin, true, false);
        }
    });
    WebViewSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setGeolocationEnabled(true);

    webView.loadUrl("http://~~~");
}
11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?