博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android webview定位权限请求
阅读量:3975 次
发布时间:2019-05-24

本文共 1655 字,大约阅读时间需要 5 分钟。

公司项目混合应用,h5界面用了百度定位,在手机系统浏览器上会弹出定位权限请求框,但在app的webview上就没响应,查看资料,发现还需要实现WebChromeClient类的onGeolocationPermissionsShowPrompt方法,步骤如下:

1、定位权限申明

2、WebView相关设置

mWebView.getSettings().setGeolocationEnabled(true);    private WebChromeClient mWebChromeClient = new WebChromeClient() {        @Override        public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) {            callback.invoke(origin, true, true);        }    };    mWebView.setWebChromeClient(mWebChromeClient);

这样完了之后有可能onGeolocationPermissionsShowPrompt不会被调用到,看这段源码说明:

/** * Notify the host application that web content from the specified origin * is attempting to use the Geolocation API, but no permission state is * currently set for that origin. The host application should invoke the * specified callback with the desired permission state. See * {@link GeolocationPermissions} for details. * * 

Note that for applications targeting Android N and later SDKs * (API level > {@link android.os.Build.VERSION_CODES#M}) * this method is only called for requests originating from secure * origins such as https. On non-secure origins geolocation requests * are automatically denied.

* * @param origin The origin of the web content attempting to use the * Geolocation API. * @param callback The callback to use to set the permission state for the * origin. */public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {}

意思是,如果targetSdkVersion设置为21以上,同时如果h5不是https开头,该方法会自动拒绝执行。解决办法是把targetSdkVersion设置为21就可以了。

转载地址:http://plrki.baihongyu.com/

你可能感兴趣的文章
LINUX驱动之IIC子系统之三I2C的数…
查看>>
LINUX驱动之IIC子系统之三I2C的数…
查看>>
Linux设备驱动之I2C架构分析
查看>>
浅析linux内核中的idr机制
查看>>
i2c子系统之__i2c_first_dynamic_b…
查看>>
linux内核SPI总线驱动分析(一)
查看>>
浅析linux内核中的idr机制
查看>>
source insight使用
查看>>
linux内核SPI总线驱动分析(一)
查看>>
linux设备模型之uart驱动架构分析
查看>>
source insight使用
查看>>
git基本使用
查看>>
七、WordPress配置HTTPS与开启CDN加速
查看>>
CentOS 6.7下MySQL 5.6 yum快速安装及参数详解
查看>>
CentOS6.8二进制安装MySQL5.6
查看>>
centos 6x系统下源码安装mysql操作记录
查看>>
Centos搭建Mysql主从复制
查看>>
centos下部署redis服务环境及其配置说明
查看>>
Centos7下部署两套python版本并存环境的操作记录
查看>>
利用阿里云的源yum方式安装Mongodb
查看>>