复制步骤:
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
谢谢
最佳答案
我错过的一件事是添加 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
在 AppManifest.xml
关于android - 权限总是返回 never_ask_again,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49771084/