【问题标题】:Permission always returns never_ask_again权限总是返回 never_ask_again
【发布时间】: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_ 中添加&lt;uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION"&gt;&lt;/uses-permission&gt; @this.lau_
  • @snjmhj 使用 react-native-permissions github.com/yonahforst/react-native-permissions
  • @snjmhj 谢谢它的工作。我认为您应该将其写在答案中,而不是写在评论中

标签: android react-native android-permissions


【解决方案1】:

我错过的一件事是在AppManifest.xml 中添加&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;&lt;/uses-permission&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2012-12-12
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 2020-11-04
    相关资源
    最近更新 更多