Reputation: 472
For the sake of testing and training I have this code.
async function testperm () {
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.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
alert('Camera ready to be used');
} else {
console.log('Permission denied');
}
}
catch (err) {
alert (err);
}
}
And the product is this
I can't find any documentation to solve this problem. The code is based on this official tutorial: https://facebook.github.io/react-native/docs/permissionsandroid
Does anyone know how to solve this. The Backend for my app is made in JAVA so if there is something I need to do in it no problem. But I don't have any Idea what to do.
Thanks.
I forgot to tell. Using Expo V 3.
Upvotes: 0
Views: 733
Reputation: 478
if you are using expo then this will do your work:
import * as Permissions from 'expo-permissions';
async testperm() {
try {
const { status, expires, permissions } = await Permissions.askAsync(
Permissions.CAMERA
);
if (status !== 'granted') {
alert('Hey! You have not enabled selected permissions');
}
if (status === 'granted') {
alert('camera permission granted');
}
}
catch (err) {
alert(err);
}
}
componentDidMount = () => {
this.testperm();
}
even you can ask multiple permissions (https://docs.expo.io/versions/latest/sdk/permissions/)
Upvotes: 1