checkAndRequestPermissions method

Future<bool> checkAndRequestPermissions({
  1. bool openSettingsIfDenied = true,
})

Checks and requests the Bluetooth permissions needed to scan and connect.

On Android 12+ (API 31+) requests:

  • Permission.bluetoothScan
  • Permission.bluetoothConnect

On Android < 12 requests:

  • Permission.bluetooth
  • Permission.locationWhenInUse (required by the OS to discover nearby devices)

On iOS requests: Checks and requests the required Bluetooth permissions according to the running OS version (supports Android 10 to Android 17+).

Returns true when every required permission is granted, false otherwise. If any permission is permanently denied and openSettingsIfDenied is true, opens the app settings so the user can enable it manually.

Implementation

Future<bool> checkAndRequestPermissions({bool openSettingsIfDenied = true}) async {
  return BluetoothPermissionHelper.checkAndRequestPermissions(
    openSettingsIfPermanentlyDenied: openSettingsIfDenied,
  );
}