权限总是返回never_ask_again

时间:2018-04-11 09:13:14

标签: android react-native android-permissions

复制步骤:

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

由于

1 个答案:

答案 0 :(得分:0)

我错过的一件事是在<uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION"></uses-permission>中添加AppManifest.xml