Search code examples
flutterlocationgoogle-play-console

Flutter App Background Location Permission Issue


Iam making a application using flutter. When a user signup and get to home page i request location permission using geolocater and save latitude and longitude in data base I only accessing it in foreground. But google play store rejected my app by saying i using background location permission

Google Play Mail Screenshot

enter image description here enter image description here

Packages

geolocator: ^9.0.2 geocoding: ^2.0.5 Importing Lines

import 'package:geocoding/geocoding.dart'; import 'package:geolocator/geolocator.dart';

Manifest File Permissions

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

Location Accessing Code

String _currentAddress = "";
  Position? _currentPosition;

  Future<bool> _handleLocationPermission() async {
    bool serviceEnabled;
    LocationPermission permission;

    serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
          content: Text(
              'Location services are disabled. Please enable the services')));
      return false;
    }
    permission = await Geolocator.checkPermission();
    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission == LocationPermission.denied) {
        ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
            content:
                Text('Location permissions are denied. Enable to Continue')));
        return false;
      }
    }
    if (permission == LocationPermission.deniedForever) {
      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
          content: Text(
              'Location permissions are permanently denied, we cannot request permissions.')));
      return false;
    }
    return true;
  }

  Future<void> _getCurrentPosition() async {
    final hasPermission = await _handleLocationPermission();

    if (!hasPermission) {
      Geolocator.openLocationSettings();
    }
    // return;
    await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
        .then((Position position) {
      setState(() => _currentPosition = position);
      _getAddressFromLatLng(_currentPosition!);
    }).catchError((e) {
      debugPrint(e);
    });
  }

  Future<void> _getAddressFromLatLng(Position position) async {
    await placemarkFromCoordinates(
            _currentPosition!.latitude, _currentPosition!.longitude)
        .then((List<Placemark> placemarks) {
      Placemark place = placemarks[0];
      // print(place.country);
      setState(() {
        _currentAddress =
            '${place.administrativeArea}, ${place.locality}, ${place.thoroughfare}, ${place.postalCode}';
      });
      // print({_currentAddress, _currentPosition});
      shop.location = _currentAddress;
      shop.longitude = _currentPosition!.longitude.toString();
      shop.latitude = _currentPosition!.latitude.toString();
      shop.pincode = place.postalCode.toString();
      isVisible = true;
      isButtonVisible = false;
    }).catchError((e) {
      debugPrint(e);
    });
  }

  @override
  void initState() {
    super.initState();
    _handleLocationPermission(); 
  }

I Already got 3 rejections from play console. I don't need background location access. How to remove background location completely from my app

Update

i removed every location permission from manifest file but still got rejected in name of this


Solution

  • Sign in to the Play Console, select the app, and then select the app package explorer from the menu. Click the arrow next to the version that has been rejected and look for the permissions section to make sure the permission isn't there. If it's there, you should find it, since it's still somewhere in your code or in one of the packages you're using.

    If it's not there, sometimes if you have an older version of the app that's currently active and you have that permission, it can cause some issues with clean uploads. In that case, from the app's package explorer, upload a new version of the app, and once the upload is complete, check again that the permission is not there. If not, please contact support: https://support.google.com/googleplay/android-developer/gethelp, explain the situation and tell them the version number of the newly uploaded version. Once you get a response from them, go ahead and attach that version to a release.