简体   繁体   English

地理定位在 TWA 内请求多个权限请求

[英]Geolocation asking for multiple permission requests inside a TWA

I am fairly new to coding so this might be noob question..我对编码相当陌生,所以这可能是菜鸟问题..

I have created a PWA and am launching it as a TWA from within android studio then publishing the app to the play store.我创建了一个 PWA 并从 android studio 中将它作为 TWA 启动,然后将应用程序发布到 Play 商店。

There is a Geolocation feature in the PWA that determine the users location when they press a specific button. PWA 中有一个 Geolocation 功能,可以确定用户按下特定按钮时的位置。

var result;

function showPosition() {
    
    result = document.getElementById("result");
    
    
    if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
        result.innerHTML = "Getting the position information...";
    } else {
        alert("Sorry, your browser does not support HTML5 geolocation.");
    }
};


function successCallback(position) {
    result.innerHTML = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")";
}

I have set up the ACCESS_FINE_LOCATION permissions in android studio and this will sucessully prompt the user for permissions when the app first launches.我已经在 android studio 中设置了 ACCESS_FINE_LOCATION 权限,这将在应用程序首次启动时成功提示用户输入权限。

This is in my android manifest这是在我的 android 清单中

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

and this is in the main activity:这是在主要活动中:

 private static final String[] GPS_PERMISSIONS = {
        Manifest.permission.ACCESS_FINE_LOCATION};


private void verifyPermissions() {

    int permissionGps = ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION);
    int permissionInternet = ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.INTERNET);

    if (permissionGps != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(
                MainActivity.this,
                GPS_PERMISSIONS,
                1

        );

This issue I face is that is is asking the user twice for location permissions.我面临的这个问题是两次询问用户位置权限。

Permissions are asked the first time when the app launches (the native prompt)应用启动时第一次询问权限(原生提示)

原生提示截图

then again when they press the button in the TWA (the HTML5 prompt)然后当他们按下 TWA 中的按钮时(HTML5 提示)

PWA 提示截图

Is it possible to share/pass the permissions from the native app to the TWA so all permissions are handled within the native app and user does not need to approve again once inside a TWA?是否可以将权限从本机应用程序共享/传递到 TWA,以便所有权限都在本机应用程序内处理,并且用户在 TWA 内无需再次批准?

Location Delegation is now stable and this shouldn't be an issue anymore.位置委派现在稳定了,这应该不再是问题了。 Check out the demo app on how to use it.查看演示应用程序以了解如何使用它。 If this behaviour persists, please file a bug at https://crbug.com如果此行为仍然存在,请在https://crbug.com提交错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM