在我检查物理位置(Android)上的React Native应用程序在调试过程中的位置权限时,即使我在设置中授予了该权限,该位置权限始终被阻止。我必须注意,以前我无法请求“询问权限”窗口,因此我无法以任何方式阻止它。另外,我尝试删除并让该应用重新安装。
这是我检查位置许可的代码(我也尝试过其他代码)。在这里我使用react-native-permissions
,但是,如果我使用PermissionsAndroid
中的react-native
,行为是相同的。
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;
}
我没有找到任何可以解释这一点的信息。我认为在调试过程中可能无法请求许可。
答案 0 :(得分:0)
最后,我找到了问题的根源。最有趣的是,它与我的代码没有任何关系。问题是由清单引起的,更确切地说,是由我所包含的规则引起的。
<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 Play使用您的应用清单中声明的元素来从不符合其硬件和软件功能要求的设备中过滤应用。
除了上述规则外,我还必须添加uses-permission
,
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />