首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查权限总是返回“拒绝”。React Native

检查权限总是返回“拒绝”。React Native
EN

Stack Overflow用户
提问于 2020-07-14 15:52:42
回答 1查看 5.5K关注 0票数 1

在物理设备(Android)上的React本地应用程序的调试过程中,当我检查位置权限时,它总是被阻塞,即使我在设置中授予了权限。我必须指出,以前我无法请求“请求许可”窗口,因此我无法以任何方式阻止它。此外,我试图删除和让应用程序再次安装。

这是我检查位置许可的代码(我也尝试过其他的)。在这里,我使用react-native-permissions,但是,如果我使用来自react-nativePermissionsAndroid,则行为是相同的。

代码语言:javascript
复制
import {check, PERMISSIONS, request, RESULTS, openSettings} from "react-native-permissions";

async function checkPermissions() {
    let response = await check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION); // <-- always blocked
    let isPermissionsGranted = false;

    if (response === RESULTS.GRANTED) {
        isPermissionsGranted = true;
    } else if (response === RESULTS.DENIED) {
        response = request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION, {
            title: "FreeLine requires permission",
            message: "FreeLine needs access to your location so you can see your position",
            buttonPositive: "Ok",
            buttonNegative: "Don't show my position",
        });

        if (response === RESULTS.GRANTED) {
            isPermissionsGranted = true;
        } else if (response === RESULTS.DENIED) {
            await openSettings();
        }
    }

    return isPermissionsGranted;
}

我还没找到任何能解释这一点的信息。我认为,在调试期间,我可能无法请求许可。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-16 03:47:41

最后,我找到了问题的根源。最有趣的是,它与我的代码没有任何关联。这个问题是由清单引起的,更确切地说,是由我所包含的规则引起的。

代码语言:javascript
复制
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-feature android:name="android.permission.BLUETOOTH" android:required="true"/>
<!-- Only foreground ble access -->
<uses-feature android:name="android.permission.ACCESS_FINE_LOCATION" android:required="true"/>

从上面的片段中可以看到,我使用了use-feature。在这里,医生们是怎么说的:

Google使用应用程序清单中声明的元素从不符合其硬件和软件功能要求的设备中筛选应用程序。

除了上述规则之外,我还必须添加uses-permission,如下所示:

代码语言:javascript
复制
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62899063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档