通常のブラウザーで正常に動作する WatchPosition 呼び出しを含む Web ページがあります。ただし、WebChromeClient を使用して WebView から Web ページが読み込まれ、onGeolocationPermissionsShowPrompt が呼び出されない場合、GPS 許可を要求するためのダイアログは表示されません。
public class GeoWebChromeClient extends WebChromeClient {
public void onGeolocationPermissionsShowPrompt(String origin, android.webkit.GeolocationPermissions.Callback callback) {
Log.d("geolocation permission", "permission >>>"+origin);
callback.invoke(origin, true, false);
}
}
public class GeoWebViewClient extends WebViewClient {
@Override
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// When user clicks a hyperlink, load in the existing WebView
view.loadUrl(url);
return true;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView Browser = (WebView) findViewById(R.id.Browser);
WebSettings webSettings = Browser.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true);
Browser.setWebViewClient(new GeoWebViewClient());
Browser.setWebChromeClient(new GeoWebChromeClient());
Browser.loadUrl("http://192.168.1.102/");
}
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />