在物理设备(Android)上的React本地应用程序的调试过程中,当我检查位置权限时,它总是被阻塞,即使我在设置中授予了权限。我必须指出,以前我无法请求“请求许可”窗口,因此我无法以任何方式阻止它。此外,我试图删除和让应用程序再次安装。
这是我检查位置许可的代码(我也尝试过其他的)。在这里,我使用react-native-permissions,但是,如果我使用来自react-native的PermissionsAndroid,则行为是相同的。
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;
}我还没找到任何能解释这一点的信息。我认为,在调试期间,我可能无法请求许可。
发布于 2020-07-16 03:47:41
最后,我找到了问题的根源。最有趣的是,它与我的代码没有任何关联。这个问题是由清单引起的,更确切地说,是由我所包含的规则引起的。
<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,如下所示:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />https://stackoverflow.com/questions/62899063
复制相似问题