flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

fix: Can we get location from background service?

Open ash-hashtag opened this issue 2 years ago • 5 comments

Description I'm trying to call Location().getLocation() from a service created by flutter_background_service plugin, since I want to get location even when app is terminated, and location plugin doesn't seem to support it

Expected behavior Somehow get location from background?

Steps To Reproduce create a service call Location().getLocation() inside the service

Tested on:

  • Android, API Level 31, real device
  • iOS, Version XX [e.g. 15], simulator or real device

Other plugins:

flutter_background_service

Additional logs

E/flutter (17736): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference in method 'void com.lyokone.location.MethodCallHandlerImpl.onGetLocation(io.flutter.plugin.common.MethodChannel$Result)', null, java.lang.NullPointerException: Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference in method 'void com.lyokone.location.MethodCallHandlerImpl.onGetLocation(io.flutter.plugin.common.MethodChannel$Result)'
E/flutter (17736):      at com.lyokone.location.MethodCallHandlerImpl.onGetLocation(MethodCallHandlerImpl.java:117)
E/flutter (17736):      at com.lyokone.location.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:43)
E/flutter (17736):      at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (17736):      at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (17736):      at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (17736):      at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (17736):      at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (17736):      at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (17736):      at android.os.Looper.loopOnce(Looper.java:233)
E/flutter (17736):      at android.os.Looper.loop(Looper.java:334)
E/flutter (17736):      at android.app.ActivityThread.main(ActivityThread.java:8278)
E/flutter (17736):      at java.lang.reflect.Method.invoke(Native Method)
E/flutter (17736):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
E/flutter (17736):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1065)
E/flutter (17736): )

ash-hashtag avatar Nov 01 '22 15:11 ash-hashtag

same problem

jjazzme avatar Nov 09 '22 12:11 jjazzme

Same problem with me too. Did you guys get the solution?

Zingworks-Sachin avatar Dec 21 '22 09:12 Zingworks-Sachin

same problem... any workaround??

Mr-Jeeva avatar Dec 29 '22 07:12 Mr-Jeeva

same issue

Dimolll avatar Jan 11 '23 23:01 Dimolll

same issue here, any workaround?

diegohzea avatar Jun 14 '23 16:06 diegohzea