Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

[android] "Can request only one set of permissions at a time."#53

Description

@daadu

馃悰 Bug Report

Calling await LocationPermissions().requestPermissions(); with both "Fine" and "Coarse" permission in AndroidManifest.xml gives the Can request only one set of permissions at a time. in the logs. Also, giving PermissionStatus.denied (even if approved) when checkPermissions called after awaiting requestPermissions.

Expected behaviour

The error/warning should not come in and correct status should be returned by checkPermissions after requestPermissions is called.

Reproduction steps

Code to reproduce:

  Future<bool> _checkLocationPermission() async {
    final checkPermission = await LocationPermissions().checkPermissionStatus();
    printIfDebug("checkPermission: $checkPermission");
    if (checkPermission == PermissionStatus.granted ||
        checkPermission == PermissionStatus.restricted) return true;
    return false;
  }

  Future<bool> _checkAndRequestLocationPermission() async {
    // return true, if already have permission
    if (await _checkLocationPermission()) return true;

    // request permission
    final _ = await LocationPermissions().requestPermissions();
    printIfDebug("requestPermission: $_");

    // check if permission was given
    final hasPermission = await _checkLocationPermission();

    // if no permission and "showShowPermissionRationale" then go to settings and return false
    if (!hasPermission &&
        await LocationPermissions().shouldShowRequestPermissionRationale()) {
      // if shouldRequest false, then open app settings and return false
      // TODO UI that shows why this permission is required
      await LocationPermissions().openAppSettings();
      return false;
    }

    return hasPermission;
  }

This is how it it is used for checking access for location before calling WifiManager.startScan api on android

  Future<List<WifiNetwork>> scanWifi() async {
    if (await _checkAndRequestLocationPermission())
      return await WiFiForIoTPlugin.loadWifiList();
    return null;
  }

Configuration

Android SDK: 28

Version: ^3.0.0

Platform:

  • 馃摫 iOS
  • 馃 Android

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions