【发布时间】:2018-09-21 02:28:56
【问题描述】:
复制步骤:
react-native init project
<add code below to the project(App.js component)>
react-native run-android
我在一个文本组件的onPress 中调用了函数。
即使是新的应用程序运行,权限请求也总是返回 never_ask_again。
async requestPermissions() {
// android 6.0 +
if (Platform.OS === 'android' && Platform.Version >= 23) {
try {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
'title': 'Let the access location',
'message': 'locate you.'
});
console.log('granted: ', granted);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
Alert.alert("Granted access", [{ text: "ok" }])
} else {
Alert.alert(
"can't access to GPS title",
"returned " + granted,
[
{ text: "ok" }
]
);
}
} catch (err) {
}
}
}
即使从设置中启用了权限,仍然会返回 never_ask_again。
React Native Version: 0.55.2
React Version: 16.3.1
在 app/build.gradle 中
targetSdkVersion 23
谢谢
【问题讨论】:
-
您有没有发现问题所在?另外对我来说,
PermissionsAndroid.check总是返回false,即使已授予权限。 -
我错过的一件事是在
AppManifest.xml@this.lau_ 中添加<uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION"></uses-permission>@this.lau_ -
@snjmhj 使用 react-native-permissions github.com/yonahforst/react-native-permissions
-
@snjmhj 谢谢它的工作。我认为您应该将其写在答案中,而不是写在评论中
标签: android react-native android-permissions