如果用户将位置权限授予“始终允许”,我的 flutter 应用程序将崩溃(继续停止)。问题仅出现在 Android 13 设备中,它可以在所有其他版本中运行。
升级后出现问题 编译SdkVersion 31 targetSdkVersion 31
之前是30,到了30就正常了。
在 app/build.gradle 中添加了这一行并尝试了 2.7.0 和 2.7.1。但它仍然不起作用
dependencies {
...
implementation 'androidx.work:work-runtime:2.7.1'
}
应用程序在此功能时崩溃
BackgroundLocator.registerLocationUpdate(
LocationCallbackHandler.callback,
iosSettings: IOSSettings(
accuracy: locset.LocationAccuracy.NAVIGATION,
distanceFilter: 0),
autoStop: false,
androidSettings: AndroidSettings(
accuracy: locset.LocationAccuracy.NAVIGATION,
wakeLockTime: wakeLockTime,
interval: interval,
distanceFilter: 0,
client: LocationClient.google,
androidNotificationSettings: AndroidNotificationSettings(
notificationChannelName: 'Location tracking',
notificationTitle: 'Location Tracking',
notificationMsg: 'Track location in background',
notificationBigMsg:
'Background location is on to keep the app up-to-date with your location. This is required for main features to work properly when the app is not running.',
notificationIconColor: Colors.grey,
notificationTapCallback:
LocationCallbackHandler.notificationCallback)));
试试这个
示例代码:
_askPermission() async {
PermissionStatus result;
if (Platform.isAndroid) {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
if (androidInfo.version.sdkInt >= 33) {
result = await Permission.locationAlways.request();
} else {
result = await Permission.location.request();
}
} else {
result = await Permission.location.request();
}
if (result.isGranted) {
// your code
} else {
await openAppSettings();
}}
对我来说,问题似乎来自 safe_device 包,它与地理定位器冲突。尝试删除该软件包或寻找解决此冲突的版本