使用webview打开网页,遇到需要定位时,可以这样设置
前提是需要先获取到定位权限

webView.setBrowserAgent(new locationRec(this));
private class locationRec extends ohos.agp.components.webengine.BrowserAgent{
        public locationRec(Context context) {
            super(context);
        }

        @Override
        public void onLocationApiAccessRequest(String origin, LocationAccessController.Response response) {
            response.apply(origin,true,false);
            super.onLocationApiAccessRequest(origin, response);
            //throw new RuntimeException("Stub!");
        }
    }
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐