Last active
March 9, 2022 11:18
-
-
Save soulduse/e5db22a33bd23ef4b816f06039f6e696 to your computer and use it in GitHub Desktop.
Android - using GPS in the 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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
U know how do it on xamarin?