gpt4 book ai didi

Android WebChromeClient WebView onGeolocationPermissionsShowPrompt 从未触发

转载 作者:太空狗 更新时间:2023-10-29 16:20:39 26 4
gpt4 key购买 nike

我有一个带有 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" />

最佳答案

onGeolocationShowPrompt 本身并不实际显示提示,它只是一种在页面请求您的地理位置时调用的方法。您需要为用户创建自己的提示,如下所示(位于 onGeolocationShowPrompt 方法内):

final boolean remember = true;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Locations");
builder.setMessage(origin + " Would like to use your Current Location").setCancelable(true).setPositiveButton("Allow",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
// origin, allow, remember
callback.invoke(origin, true, remember);
}
})
.setNegativeButton("Don't Allow",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
// origin, allow, remember
callback.invoke(origin, false, remember);
}
});
AlertDialog alert = builder.create();
alert.show();

关于Android WebChromeClient WebView onGeolocationPermissionsShowPrompt 从未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15840879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com