我正在使用 flutter 制作一个应用程序。当用户注册并进入主页时,我使用 geolocater 请求位置权限并将经纬度保存在数据库中 我只在前台访问它。 但是 google play 商店拒绝了我的应用,说我使用了后台位置权限
Google Play 邮件截图
套餐
geolocator: ^9.0.2 geocoding: ^2.0.5
导入线
import 'package:geocoding/geocoding.dart'; import 'package:geolocator/geolocator.dart';
清单文件权限
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
位置访问代码
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();
}
我已经被 Play 控制台拒绝了 3 次。我不需要后台位置访问权限。如何从我的应用程序中完全删除背景位置
我从清单文件中删除了所有位置权限,但仍然以这个名义被拒绝
你所要做的就是添加
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCAITON" />
给你的
app/src/main/AndroidManifest.xml
在申请部分下