当前位置:网站首页>Set the location permission in the shutter to "always allow"

Set the location permission in the shutter to "always allow"

2022-06-25 09:43:00 Moon Spring

Link to the original text :https://www.5axxw.com/questions/content/6zrs4y
Use permission_handler After setting the location permission, only ’ Allow... Only when using the app ’, After looking for a while, I couldn't find the reason . The link above solves my problem .

 ///  Dynamically apply for location permission 
  void requestPermission() async {
    
    //  Application authority 
    bool hasLocationPermission = await requestLocationPermission();
    if (hasLocationPermission) {
    
      print(" The application for location permission passed ");
    } else {
    
      print(" The application for location permission fails ");
    }
  }

  ///  Apply for location rights 
  ///  Granting location permission returns true,  Otherwise return to false
  Future<bool> requestLocationPermission() async {
    
    // Get current permissions 
    var locationWhenInUse = await Permission.location.status;
    if (locationWhenInUse == PermissionStatus.granted) {
    
      // Has authorized 
      return true;
    } else {
    
      // If not authorized, initiate an application 
      locationWhenInUse = await Permission.location.request();
      if (locationWhenInUse == PermissionStatus.granted) {
    
        return true;
      } else {
    
        return false;
      }
    }
  }
  
//***************************** Split line *************************************************//
AndroidManifest.xml Used in 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " />

 Adding a permission 
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

 Then, there are... In the location permission settings “ Always allow ” The choice of .


原网站

版权声明
本文为[Moon Spring]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200549006192.html