Flutter-地理位置上的java.lang.IllegalStateException

问题描述

我的项目上有此类,该类返回设备的位置。当我在android模拟器上运行它时,获取当前位置没有问题,而且当我使用具有双SIM卡的其他物理设备时也是如此。但是,当我在具有双SIM卡网络的RedMi Note 7上运行它时,它不起作用,我尝试禁用其他SIM卡,重新启动了手机,而且我已经开启和关闭了飞行模式,但只能运行一次,我不知道是什么问题。我还看到了使用ADB logcat的异常。见下文

class LocationService {
  final DialogService _dialogService = locator<DialogService>();
  Position _currentPos;
  Position get currentPos => _currentPos;
  Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
  Future getCurrentLocation() async {
    try {
      if(await Permission.location.isDenied || await Permission.location.isPermanentlyDenied || await     Permission.location.isRestricted ||await Permission.location.isUndetermined ) {
        await Permission.locationAlways.request();
        _currentPos = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
        print(_currentPos);
      } else {
        _currentPos = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
        print(_currentPos);
      }
    } catch (e) {
      await _dialogService.showDialog(
        title: 'Location Access Denied',description: 'You can turn on your device\'s location on your phone\'s settings.',);
      return null;
    }

  }

  void showToast(message) {
    Fluttertoast.showToast(
      msg: message,toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.BOTTOM,timeInSecForIosWeb: 1,backgroundColor: Colors.red,textColor: Colors.white,fontSize: 16.0,);
  }
}

使用ADB logcat的日志:

08-19 21:42:37.218  3713  3999 I NetworkLocationManager: start get current Location
08-19 21:42:37.219  3713  3713 I MetokLocationProvider: report position from 2
08-19 21:42:37.493 23005 23005 I subsystem_ramdump: Usage:./system/bin/subsystem_ramdump [arg1] [arg2] [arg3]
08-19 21:42:37.493 23005 23005 I subsystem_ramdump: [arg1]: (1/2) Ramdump location: 1: eMMC: /data/vendor/ramdump or 2: SD card: /sdcard/ramdump
08-19 21:42:37.493 23005 23005 I subsystem_ramdump: [arg2]: (1/0) 1: Enable RPM log / 0: Disable RPM log
08-19 21:42:37.493 23005 23005 I subsystem_ramdump: [arg3]: (1/0) 1: Enable qdss ramdump / 0: Disable qdss ramdump
08-19 21:42:37.493 23005 23005 I subsystem_ramdump:  Using default ramdump location 1: eMMC: /data/vendor/ramdump
08-19 21:42:37.483 23005 23005 W subsystem_ramdu: type=1400 audit(0.0:3860): avc: denied { read } for name="enable_ramdumps" dev="sysfs" ino=25533 scontext=u:r:vendor_subsystem_ramdump:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0
08-19 21:42:37.493 23005 23005 I subsystem_ramdump:  Using default 0: Disable RPM log
08-19 21:42:37.493 23005 23005 I subsystem_ramdump:  Using default 0: Disable qdss ramdump
08-19 21:42:37.493 23005 23005 E subsystem_ramdump: Unable to open /sys/module/subsystem_restart/parameters/enable_ramdumps
08-19 21:42:37.516  4500  5810 W MessageQueue: Handler (android.location.LocationManager$GnssStatusListenerTransport$GnssHandler) {7798ff5} sending message to a Handler on a dead thread
08-19 21:42:37.516  4500  5810 W MessageQueue: java.lang.IllegalStateException: Handler (android.location.LocationManager$GnssStatusListenerTransport$GnssHandler) {7798ff5} sending message to a Handler on a dead thread
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.MessageQueue.enqueueMessage(MessageQueue.java:561)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Handler.enqueueMessage(Handler.java:754)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Handler.sendMessageAtTime(Handler.java:703)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Handler.sendMessageDelayed(Handler.java:673)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Handler.sendMessage(Handler.java:611)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Message.sendToTarget(Message.java:474)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.location.LocationManager$GnssStatusListenerTransport.onSvStatusChanged(LocationManager.java:1779)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.location.IGnssStatusListener$Stub.onTransact(IGnssStatusListener.java:142)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Binder.execTransactInternal(Binder.java:1021)
08-19 21:42:37.516  4500  5810 W MessageQueue:  at android.os.Binder.execTransact(Binder.java:994)
08-19 21:42:37.734  1941  1975 D HBMFeatureControl: light lux=33.0
08-19 21:42:37.737  2145  2558 D NetworkController.MobileSignalController(1): 4G level = 5
08-19 21:42:37.936  1941  1975 D HBMFeatureControl: light lux=38.0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...