/**
* 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裡沒有任何反應這是為什麼呢?我非常的困擾。我非常的不解,我想問下,大家是這麼寫的,還是說還要配置其他的什麼嗎?
好像是自動賦予權限的,你再設定裡面把權限去掉再看呢