javascript - 深夜被問題困擾求解惑,rn的API之PermissionsAndroidd的問題
問題描述
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, { Component } from ’react’;import { AppRegistry, StyleSheet, Text, View, PermissionsAndroid, Platform} from ’react-native’;async function requestCameraPermission() { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.CAMERA, {’title’: ’Cool Photo App Camera Permission’,’message’: ’Cool Photo App needs access to your camera ’ + ’so you can take awesome pictures.’ } ) if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('You can use the camera') } else { console.log('Camera permission denied') } } catch (err) { console.warn(err) }}requestCameraPermission()if(Platform.Version === 23){ console.log(’Running on Lollipop!’);}export default class myproject2 extends Component { render() { return ( <View style={styles.container}><Text style={styles.welcome}> Welcome to React Native!</Text><Text style={styles.instructions}> To get started, edit index.android.js</Text><Text style={styles.instructions}> Double tap R on your keyboard to reload,{’n’} Shake or press menu button for dev menu</Text> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, justifyContent: ’center’, alignItems: ’center’, backgroundColor: ’#F5FCFF’, }, welcome: { fontSize: 20, textAlign: ’center’, margin: 10, }, instructions: { textAlign: ’center’, color: ’#333333’, marginBottom: 5, },});AppRegistry.registerComponent(’myproject2’, () => myproject2);
問題是這樣的,我想獲取某個權限,看過官網的API也查了一些資料我在AndroidManifest.xml里面是配置過的,手機和模擬器都是安卓6.0的,SDK的版本是23都是沒有問題,但是我在測試的時候就發現,當我調用了,他是直接返回true的,顯示的是You can use the camera,在瀏覽器的控制臺里,但是APP里沒有任何反應這是為什么呢?我非常的困擾。我非常的不解,我想問下,大家是這么寫的,還是說還要配置其他的什么嗎?
問題解答
回答1:好像是自動賦予權限的,你再設置里面把權限去掉再看呢
