snj*_*mhj 7 android android-permissions react-native
复制步骤:
react-native init project
<add code below to the project(App.js component)>
react-native run-android
Run Code Online (Sandbox Code Playgroud)
我调用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) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
即使从设置启用了权限,仍会返回never_ask_again.
React Native Version: 0.55.2
React Version: 16.3.1
Run Code Online (Sandbox Code Playgroud)
在app/build.gradle中
targetSdkVersion 23
Run Code Online (Sandbox Code Playgroud)
谢谢
snj*_*mhj 14
我错过的一件事是<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>添加AppManifest.xml