OZEO-DOOZ / nrf_mesh_plugin

A Flutter plugin to enable mesh network management and communication using Nordic Semiconductor's SDKs.
https://pub.dev/packages/nordic_nrf_mesh
BSD 3-Clause "New" or "Revised" License
28 stars 19 forks source link

Example app requires Android Location Permissions but does not request for it #242

Closed movaid7 closed 2 years ago

movaid7 commented 2 years ago

Within the Provisioning and Control tabs, the example app fails to find modules if Location Permissions are not granted. However, the app never asks the user for device location access. Modules are found once the app is manually granted Location Permissions.

Example

Default App behaviour

After manually adding location permissions

ghost commented 2 years ago

Hello @movaid7 ! Indeed, from android 6 to 11, location permission is needed along with the ble one. We didn't put the permission requests so the app is as simple as possible, but you probably want to import permission_handler pkg to handle it.

With the release of Android 12, the logic should be :

I will give you a snippet to handle it properly 👍 We may also add it to the example app or in the readme for better understanding

ghost commented 2 years ago

Something like this :

  Future<void> _checkAndAskPermissions() async {
    final androidInfo = await DeviceInfoPlugin().androidInfo;
    if (androidInfo.version.sdkInt! < 31) {
      // location
      final locationPermission = await Geolocator.checkPermission();
      if (locationPermission != LocationPermission.always &&
          locationPermission != LocationPermission.whileInUse) {
        _log('location permission is needed');
        await Geolocator.requestPermission();
      }
      // bluetooth
      final bluetoothPermission = await Permission.bluetooth.status;
      if (bluetoothPermission == PermissionStatus.granted) {
        _log('all good permissions');
      } else {
        _log('BLE permission is needed');
        await Permission.bluetooth.request();
      }
    } else {
      // bluetooth for Android 12 and up
      final bluetoothScan = await Permission.bluetoothScan.status;
      final bluetoothConnect = await Permission.bluetoothConnect.status;
      if (bluetoothScan == PermissionStatus.granted &&
          bluetoothConnect == PermissionStatus.granted) {
        _log('all good permissions');
      } else {
        _log('some BLE permissions are needed');
        await Permission.bluetoothScan.request();
        await Permission.bluetoothConnect.request();
      }
    }
  }

There are 3 pkgs involved 😅 but you may not need geolocator 🤔

movaid7 commented 2 years ago

That should do the trick 👌