即使在 Ar.js 中的浏览器中授予权限后,地理定位访问被拒绝弹出窗口也会显示

Posted

技术标签:

【中文标题】即使在 Ar.js 中的浏览器中授予权限后,地理定位访问被拒绝弹出窗口也会显示【英文标题】:Geoloaction acess denied pop-up showing even after permission granted in browser in Ar.js 【发布时间】:2020-07-05 08:44:48 【问题描述】:

我正在尝试在 android webview 中使用 Ar.js,在授予位置和相机权限后,我收到一个对话框,提示无法访问地理位置 [![like this][1]][1]。

当出现此对话框时,在日志中我收到一条错误消息ERROR(1): User denied Geolocation。这是完整的日志:

07-05 13:33:46.355 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(0)] "The connection used to load resources from used TLS 1.0 or TLS 1.1, which are deprecated and will be disabled in the future. Once disabled, users will be prevented from loading these resources. The server should enable TLS 1.2 or later. See https://www.chromestatus.com/feature/5654791610957824 for more information.", source: 
07-05 13:33:47.176 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(140)] "No DPDB device match.", source: https://aframe.io/releases/0.9.2/aframe.min.js (140)
07-05 13:33:47.176 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(140)] "Failed to recalculate device parameters.", source: https://aframe.io/releases/0.9.2/aframe.min.js (140)
07-05 13:33:47.183 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(140)] "Using fallback Android device measurements.", source: https://aframe.io/releases/0.9.2/aframe.min.js (140)
07-05 13:33:47.399 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(259)] "document.registerElement is deprecated and will be removed in M73, around March 2019. Please use window.customElements.define instead. See https://www.chromestatus.com/features/4642138092470272 for more details.", source: https://aframe.io/releases/0.9.2/aframe.min.js (259)
07-05 13:33:47.520 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(353)] "A-Frame Version: 0.9.2 (Date 2019-05-06, Commit #f57a1fa)", source: https://aframe.io/releases/0.9.2/aframe.min.js (353)
07-05 13:33:47.520 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(353)] "three Version (https://github.com/supermedium/three.js):", source: https://aframe.io/releases/0.9.2/aframe.min.js (353)
07-05 13:33:47.521 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(353)] "WebVR Polyfill Version:", source: https://aframe.io/releases/0.9.2/aframe.min.js (353)
07-05 13:33:47.806 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(140)] "No DPDB device match.", source: https://aframe.io/releases/0.9.2/aframe.min.js (140)
07-05 13:33:47.807 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(140)] "Failed to recalculate device parameters.", source: https://aframe.io/releases/0.9.2/aframe.min.js (140)
07-05 13:33:48.429 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(95)] "THREE.WebGLRenderer", source: https://aframe.io/releases/0.9.2/aframe.min.js (95)
07-05 13:33:49.551 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(4120)] "ERROR(1): User denied Geolocation", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (4120)
07-05 13:33:53.448 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(2612)] "AR.js", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (2612)
07-05 13:33:54.930 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(2)] "[warning] *** Camera Parameter resized from 640, 480. ***", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (2)
07-05 13:33:55.161 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(2)] "[info] Allocated videoFrameSize 307200", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (2)
07-05 13:33:55.175 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(2)] "[info] Pattern detection mode set to 1.", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (2)
07-05 13:33:55.189 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(2)] "[info] Pattern ratio size set to 0.500000.", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (2)
07-05 13:33:55.189 32209-32209/com.example.sample I/chromium: [INFO:CONSOLE(2)] "[info] Labeling mode set to 1", source: https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js (2)

我已经在 android chrome 中检查了位置权限,并且位置权限在那里处于活动状态。

在这个弹出窗口之后,我得到另一个弹出窗口(即使我使用的是 Android) [![this][2]][2]

因此,我在放置 A-frame 的球体组件时遇到了麻烦,这也是 Ar.js 的起始问题。请帮帮我。

【问题讨论】:

设备方向确实需要不同的权限,我认为您应该尝试使用包含授权弹出框的最新A-Frame版本(1.0.4)。 @StéphaneAlbanese 进行回复,但即使使用 A-Frame 版本(1.0.4)和此处的链接aframe.io/docs/1.0.0/components/… 问题仍然存在,实际上添加device-orientation-permission-ui="enabled: true" 并没有做任何事情 【参考方案1】:

我正在回答我自己的问题,以便它可以帮助将来遇到同样问题的任何人。

罪魁祸首是在不同的地方两次使用 setWebChromeClient(),如下所示。

   webView.setWebChromeClient(new WebChromeClient() 
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) 
            callback.invoke(origin, true, false);
        
    );

    webView.setWebChromeClient(new WebChromeClient() 
        @Override
        public void onPermissionRequest(final PermissionRequest request) 
            final String[] requestedResources;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) 
                requestedResources = request.getResources();
                for (String r : requestedResources) 
                    if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) 
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
                            request.grant(new String[]PermissionRequest.RESOURCE_VIDEO_CAPTURE);
                        
                        break;
                    
                
            

        
    );



将其更改为单个 setWebChromeClient()(如下所示),第一个弹出窗口消失了。第二个弹出窗口现在只在安装应用程序时出现一次,到目前为止不会造成任何问题。(如果将来出现,我会更新答案)。

webView.setWebChromeClient(new WebChromeClient() 
            public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) 
                callback.invoke(origin, true, false);
            

            @Override
            public void onPermissionRequest(final PermissionRequest request) 
                final String[] requestedResources;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) 
                    requestedResources = request.getResources();
                    for (String r : requestedResources) 
                        if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) 
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
                                request.grant(new String[]PermissionRequest.RESOURCE_VIDEO_CAPTURE);
                            
                            break;
                        
                    
                

            
        );


    

【讨论】:

以上是关于即使在 Ar.js 中的浏览器中授予权限后,地理定位访问被拒绝弹出窗口也会显示的主要内容,如果未能解决你的问题,请参考以下文章

即使在 Flutter 中授予权限后,通知访问屏幕也会不断弹出

即使在授予存储权限后权限也被拒绝

Android kotlin:即使在授予权限后也获得 EACCES(权限被拒绝)

W3C 地理位置,错误:位置不可用

即使授予存储权限后,在三星手机上创建目录也被拒绝

S3 存储桶策略授予/限制对特定联合用户的访问权限