Skip to content

[Bug]: App crashes when calling getCurrentPosition() #1515

Description

@muhammad67uzair

Please check the following before submitting a new issue.

Please select affected platform(s)

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Steps to reproduce

  1. add the geolocator plugin
  2. add the access.coarse.location permission in androidmanifest.xml
  3. call geolocator.getCurrentPosition();

Expected results

the coarse location/position of the user should be returned.

Actual results

App crashes when calling geolocator.getCurrentPosition();
i have added the android.permission.ACCESS_COARSE_LOCATION in my AndroidManifest.xml file, but when the app requests the user's current position the app crashes with the following exception:

D/AndroidRuntime(11738): Shutting down VM
E/AndroidRuntime(11738): FATAL EXCEPTION: main
E/AndroidRuntime(11738): java.lang.SecurityException: Neither user 10373 nor current process has android.permission.ACCESS_FINE_LOCATION.

although im not even requesting user's fine location.

I even tried specifying a specific geolocator version like 11.0.0 and previous ones but to no avail.

complete error log:

E/AndroidRuntime(11738): java.lang.SecurityException: Neither user 10373 nor current process has android.permission.ACCESS_FINE_LOCATION.
E/AndroidRuntime(11738): at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
E/AndroidRuntime(11738): at android.os.Parcel.createException(Parcel.java:3041)
E/AndroidRuntime(11738): at android.os.Parcel.readException(Parcel.java:3024)
E/AndroidRuntime(11738): at android.os.Parcel.readException(Parcel.java:2966)
E/AndroidRuntime(11738): at android.location.ILocationManager$Stub$Proxy.registerGnssNmeaCallback(ILocationManager.java:1625)
E/AndroidRuntime(11738): at android.location.LocationManager$GnssNmeaTransportManager.registerTransport(LocationManager.java:3127)
E/AndroidRuntime(11738): at android.location.LocationManager$GnssNmeaTransportManager.registerTransport(LocationManager.java:3117)
E/AndroidRuntime(11738): at com.android.internal.listeners.ListenerTransportManager.addListener(ListenerTransportManager.java:70)
E/AndroidRuntime(11738): at android.location.LocationManager.addNmeaListener(LocationManager.java:2629)
E/AndroidRuntime(11738): at android.location.LocationManager.addNmeaListener(LocationManager.java:2610)
E/AndroidRuntime(11738): at com.baseflow.geolocator.location.NmeaClient.start(NmeaClient.java:76)
E/AndroidRuntime(11738): at com.baseflow.geolocator.location.FusedLocationClient.requestPositionUpdates(FusedLocationClient.java:157)
E/AndroidRuntime(11738): at com.baseflow.geolocator.location.FusedLocationClient.lambda$startPositionUpdates$2$com-baseflow-geolocator-location-FusedLocationClient(FusedLocationClient.java:240)
E/AndroidRuntime(11738): at com.baseflow.geolocator.location.FusedLocationClient$$ExternalSyntheticLambda3.onSuccess(Unknown Source:4)
E/AndroidRuntime(11738): at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.1.0:1)
E/AndroidRuntime(11738): at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime(11738): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(11738): at android.os.Looper.loopOnce(Looper.java:224)
E/AndroidRuntime(11738): at android.os.Looper.loop(Looper.java:318)
E/AndroidRuntime(11738): at android.app.ActivityThread.main(ActivityThread.java:8720)
E/AndroidRuntime(11738): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11738): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
E/AndroidRuntime(11738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
E/AndroidRuntime(11738): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(11738): at android.app.ContextImpl.enforce(ContextImpl.java:2343)
E/AndroidRuntime(11738): at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:2371)
E/AndroidRuntime(11738): at com.android.server.location.gnss.GnssManagerService.registerGnssNmeaCallback(GnssManagerService.java:206)
E/AndroidRuntime(11738): at com.android.server.location.LocationManagerService.registerGnssNmeaCallback(LocationManagerService.java:1151)
E/AndroidRuntime(11738): at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:809)
E/AndroidRuntime(11738):
2
W/VideoCapabilities(11738): Unsupported mime image/vnd.android.heic
W/ScoutUtils(11738): Failed to mkdir /data/miuilog/stability/memleak/heapdump/
I/Process (11738): Process is going to kill itself!
I/Process (11738): java.lang.Exception
I/Process (11738): at android.os.Process.killProcess(Process.java:1356)
I/Process (11738): at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:174)
I/Process (11738): at org.chromium.base.JavaExceptionReporter.uncaughtException(chromium-TrichromeWebViewGoogle6432.aab-stable-636712333:27)
I/Process (11738): at com.datadog.android.error.internal.DatadogExceptionHandler.uncaughtException(DatadogExceptionHandler.kt:98)
I/Process (11738): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1071)
I/Process (11738): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1066)
I/Process (11738): at java.lang.Thread.dispatchUncaughtException(Thread.java:2306)
Lost connection to device.

Code sample

Code sample
  Future<void> _updateUserLocation() async {
    LocationPermission permission = await Geolocator.checkPermission();
    if (<LocationPermission>[LocationPermission.denied, LocationPermission.deniedForever]
        .contains(permission)) {
      permission = await Geolocator.requestPermission();
      if (<LocationPermission>[
        LocationPermission.denied,
        LocationPermission.deniedForever,
      ].contains(permission)) {
        throw Exception(
          'Location permissions are permanently denied, we cannot request permissions.',
        );
      }
    }
    permission = await Geolocator.checkPermission();
    if (<LocationPermission>[LocationPermission.whileInUse, LocationPermission.always]
        .contains(permission)) {
      final Position position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high,
      );
  }

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

12.0.0

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.4.1 23E224 darwin-arm64, locale
    en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.89.1)
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for Avialdo’s iPhone Xr. Ensure
      the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code
      -27)
    ! Error: Browsing on the local area network for Avialdo Solutions’s iPhone
      12 mini. Ensure the device is unlocked and attached with a cable or
      associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code
      -27)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions