I’m trying to get permissions to use bluetooth in Android, I’ve tried different options, both single and multiple requests, but I don’t get permission requests. Moreover, requests for camera or other permissions appear
Code:
const requestPermissions = async () => {
try {
const bluetoothPermission = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH,
{
title: 'Bluetooth Permission',
message: 'This app needs Bluetooth access to scan for devices.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
}
);
const bluetoothAdminPermission = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_ADMIN,
{
title: 'Bluetooth Admin Permission',
message: 'This app needs Bluetooth Admin access to manage Bluetooth settings.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
}
);
const locationPermission = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Location Permission',
message: 'This app needs location access to scan for Bluetooth devices.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
}
);
if (
bluetoothPermission !== PermissionsAndroid.RESULTS.GRANTED ||
bluetoothAdminPermission !== PermissionsAndroid.RESULTS.GRANTED ||
locationPermission !== PermissionsAndroid.RESULTS.GRANTED
) {
Alert.alert('Bluetooth permissions not granted');
}
} catch (err) {
console.error('Error requesting permissions:', err);
}
};
Also I tried this:
const result = await requestMultiple([
New contributor
Vyacheslav Bogachev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.