-
-
Save focus-at/d004206004cc1ac3a6e82a497fe9ac96 to your computer and use it in GitHub Desktop.
Android - using GPS in the WebView
This file contains hidden or 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