3
我得到這個錯誤:爲什麼PermissionAndroid不起作用?
Reference Error: can't find variable PermissionsAndroid
這是我的代碼:
的AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
index.android.js:
constructor(props) {
super(props);
this.state = {
message: 'Hi world'
};
this.requestCameraPermission();
}
async requestCameraPermission() {
try {
const granted = await PermissionsAndroid.requestPermission(
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)
}
}