如果用户将位置权限授予“始终允许”,我的 flutter 应用程序就会崩溃(继续停止)。问题仅出现在 Android 13 设备中

问题描述 投票:0回答:2

如果用户将位置权限授予“始终允许”,我的 flutter 应用程序将崩溃(继续停止)。问题仅出现在 Android 13 设备中,它可以在所有其他版本中运行。

升级后出现问题 编译SdkVersion 31 targetSdkVersion 31

之前是30,到了30就正常了。

  • 颤振版本:1.22.6
  • 背景定位器:^1.3.0+1
  • 地理定位器:^6.2.1

在 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)));
android flutter background geolocation flutter-dependencies
2个回答
2
投票

试试这个

  • permission_handler:^10.4.2
  • 设备信息_plus:^9.0.2

示例代码:

 _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();
}}

0
投票

对我来说,问题似乎来自 safe_device 包,它与地理定位器冲突。尝试删除该软件包或寻找解决此冲突的版本

© www.soinside.com 2019 - 2024. All rights reserved.