I am using this code to handle Bluetooth scan, but in Android 11, if my Bluetooth is not on, and location permission is also not granted, yet it is showing permission granted. If I go to App permissions in settings, I see no permission granted.
Here is the code:
Future requestBluetoothPermission() async {
var status = await Permission.bluetoothScan.request();
if (status.isGranted) {
print("Bluetooth scan permission granted");
} else if (status.isDenied) {
await Permission.bluetooth.request();
} else if (status.isPermanentlyDenied) {
await openAppSettings();
} else {
print("Bluetooth scan permission denied");
}
}
2
Answers
For android
you have to put theese permissions on manifest file.It works fine android 8 ,9, 10, 11, 12, 13 ,14 . I don’t know IOS permissions.
It’s worth using a package that handles the bluetooth permissions for you such as https://pub.dev/packages/flutter_blue_plus
If you want location permission enabled you’ll need to add this:
Android > android/app/src/main/AndroidManifest.xml
iOS > ios/Runner/Info.plist
Once thats done, you can add this code and listen to bluetooth events
Once you’ve added the package, updated the manifest / plist, and if you’re still developing your app, i’d reccomend deleting the app so permissions will be reset and trying again
If you need finer permission handling, then at that point i’d reccomend using the https://pub.dev/packages/permission_handler package so you can have more control over whats going on, in a similar way to this