Reputation: 26567
I get this error:
Reference Error: can't find variable PermissionsAndroid
This is my code:
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)
}
}
Upvotes: 4
Views: 5417
Reputation: 6679
Probably you forgot to import the component before using it:
import { PermissionsAndroid } from 'react-native';
Upvotes: 11