Skip to content

Instantly share code, notes, and snippets.

@soulduse
Last active March 9, 2022 11:18
Show Gist options
  • Save soulduse/e5db22a33bd23ef4b816f06039f6e696 to your computer and use it in GitHub Desktop.
Save soulduse/e5db22a33bd23ef4b816f06039f6e696 to your computer and use it in GitHub Desktop.
Android - using GPS in the WebView
package com.dave.webviewgps;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private static final String URL_NAVER_MAP = "http://m.map.naver.com/";
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true); // 자바스크립트 사용을 허용한다.
webView.setWebViewClient(new WebViewClient()); // 새로운 창을 띄우지 않고 내부에서 웹뷰를 실행시킨다.
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
super.onGeolocationPermissionsShowPrompt(origin, callback);
callback.invoke(origin, true, false);
}
});
webView.loadUrl(URL_NAVER_MAP);
}
}
Copy link

ghost commented Mar 30, 2021

U know how do it on xamarin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment