Reputation: 6591
am using following code base to request the permission but it always return 'never ask again'
async requestPermission(request){
try{
const response= 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.'
})
console.log(response)
}catch(err){
}
this.getcurrentLocation()
}
//Response never_ask_again
Upvotes: 8
Views: 9896
Reputation: 41
My suggestion to handle such situations is to open settings and direct the users directly to adapt the right, see below example:
import { Linking } from 'react-native';
import { Alert } from 'react-native';
const openSettings = () => {
Linking.openSettings();
};
const askForPermission = async () => {
try {
const result = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: 'Storage Permission',
message: 'App needs access to your storage to read files',
buttonPositive: 'OK',
buttonNegative: 'Cancel',
},
);
if (result === PermissionsAndroid.RESULTS.GRANTED) {
console.log('Storage Permission Granted.');
} else if (result === PermissionsAndroid.RESULTS.DENIED) {
console.log('Storage Permission Denied.');
} else if (result === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) {
console.log('Storage Permission Denied with Never Ask Again.');
Alert.alert(
'Storage Permission Required',
'App needs access to your storage to read files. Please go to app settings and grant permission.',
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'Open Settings', onPress: openSettings },
],
);
}
} catch (err) {
console.log(err);
}
};
Upvotes: 1
Reputation: 865
I recently faced this issue about LOCATION service permission. I forgot to add android.permission.ACCESS_FINE_LOCATION in AndroidManifest.xml.
So, I think you also forgot to add
<uses-permission android:name="android.permission.CAMERA" />
in your AndroidManifest.xml
Upvotes: 2
Reputation: 1
Removing tools:node="remove"
from AndroidManifest.xml fixed mine.
Replace
<uses-permission tools:node="remove" android:name="android.permission.CAMERA"/>
with
<uses-permission android:name="android.permission.CAMERA"/>
https://github.com/zoontek/react-native-permissions/issues/504#issuecomment-914417383
Upvotes: 0
Reputation: 6591
I did clean and rebuild several times and finally started working, somehow the build cache is not properly updating.
Upvotes: 1