【发布时间】:2019-05-13 15:51:03
【问题描述】:
我想启用我的设备的位置(android pie)。我已经阅读了 react-native 权限的文档,然后尝试实现它,但每次它都说“位置权限被拒绝”。我什至尝试使用外部库(react-native-permissions)然后它说:-“未确定:尚未提示用户使用权限对话框”。我也在清单中给出了权限(FINE_LOCATION 和 COARSE_LOCATION)。我什至尝试在应用程序权限中手动授予权限,但仍然显示权限被拒绝。如何启用位置信息。
代码如下:
async requestLocationPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Example App",
message: "Example App access to your location "
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the location");
alert("You can use the location");
} else {
console.log("location permission denied");
alert("Location permission denied");
}
} catch (err) {
console.warn(err);
}
}
在 componentDidMount 中调用它:
componentDidMount(){
this.requestLocationPermission();
}
【问题讨论】:
-
targetSdkVersion里面的android/app/build.gradle是什么? -
28 targetSdkVersion...buidtoolVersion 是 28.0.3
标签: react-native permissions geolocation android-permissions