我有一个带有 WatchPosition 调用的网页,它在常规浏览器中运行良好。但是,当使用 WebChromeClient 从 WebView 加载网页并且永远不会调用 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" />