Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 'The location service on the device is disabled' when wifi + (wifi scan / location accuracy) is disabled #1608

Closed
3 of 8 tasks
thedeukalion opened this issue Nov 19, 2024 · 4 comments
Assignees
Labels
status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. status: needs more info We need more information before we can continue work on this issue.

Comments

@thedeukalion
Copy link

Please check the following before submitting a new issue.

Please select affected platform(s)

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

Steps to reproduce

Disable wi-fi on device
Location accuracy is disabled (wifi scan)
Location services is enabled
Attempt to listen to Geolocator.getPositionStream()

Expected results

If LocationServices is said to be enabled - why get an error that it's disabled?
A way to check for this beforehand would be better.
Or fallback to GPS if possible.

Also, this issue should be resolvable by this dialog prompted by the system:
IMG_20241119_124353

And checkable:
https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient#isGoogleLocationAccuracyEnabled()

Actual results

Error message 'The location service on the device is disabled'
When in fact it's wifi-scanning / location accuracy turned off

Code sample

Code sample
var enabled = await Geolocator.isLocationServiceEnabled() == true
var granted = await Geolocator.checkPermission() == LocationPermission.whileInUse
 || await Geolocator.checkPermission() == LocationPermission.always;
var accurate = await Geolocator.getLocationAccuracy() == LocationAccuracyStatus.precise;
var settings = AndroidSettings(
        accuracy: LocationAccuracy.best,
        distanceFilter: 5,
        intervalDuration: Duration(milliseconds: 1000),
        foregroundNotificationConfig: ForegroundNotificationConfig(
          notificationText: "GPS",
          notificationTitle: "App",
          enableWakeLock: true,
          setOngoing: true,
          notificationIcon: const AndroidResource(name: "ic_notification", defType: "drawable")
        )
      );

if (enabled && granted && accurate)
{
   var stream = Geolocator.getPositionStream(locationSettings: settings)
       .asyncMap((event) => _getCoordinate(event));

   var subscription = stream.listen(onLocationChanged)
     // Log error is called with the text 'The location service on the device is disabled'.
      ..onError((error) => logError(error))
      ..onDone(() => logDone());

}

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

13.0.1

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.4, on Microsoft Windows [Version 10.0.22631.4460], locale en-SE)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.5)
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.95.3)
[✓] Connected device (2 available)
[✓] Network resources
@thedeukalion
Copy link
Author

thedeukalion commented Nov 19, 2024

I just noticed another issue with this.
If I remove the 'ForegroundNotificationConfig' and listen to getPositionStream() - the prompt above will be shown.
If I add it, it will just log as an error logged out via console (if I listen to onError). Is this intended?
Why not allow the user to "fix" this wifi scan issue before listening to location updates?
Is this due to the fact that the prompt is shown from a foreground service and thus will not show the prompt?
And there's no option to "check" for it in Geolocator before calling getPositionStream() (you can do this natively in Android) - this should somehow be added perhaps. Unless there's a working library already for it (can't seem to find it though...).

Still, the issue seems to remain regardless.
It is just logged silently in the background and no location updates is sent to the app.

@TimHoogstrate TimHoogstrate self-assigned this Dec 3, 2024
@TimHoogstrate
Copy link
Contributor

Dear @thedeukalion,

Can you elaborate a bit on the subject. I find It hard to find your question.

First, Location accuracy is disabled (wifi scan) and you get an OS alert that you need to enable it. It is not about Location Services.
Second, Feel free to add an implementation to check it before hand. We encourage you to propose an PR.
3rd, fallback for GPS is managed by the OS. You can switch on the forceLocationManager if you like to use GPS.
4th, what error does it log to the console?

Kind regards,

@TimHoogstrate TimHoogstrate added the status: needs more info We need more information before we can continue work on this issue. label Dec 11, 2024
Copy link

Without additional information, we are unfortunately not able to resolve this issue. Therefore, we reluctantly closed this issue for now. If you run into this issue later, feel free to file a new issue with a reference to this issue. Add a description of detailed steps to reproduce, expected and current behaviour, logs and the output of 'flutter doctor -v'. Thanks for your contribution.

@github-actions github-actions bot added the status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. label Dec 25, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 25, 2024
@m4ta1
Copy link

m4ta1 commented Feb 12, 2025

I ran into the same issue. Using Geolocator 13.0.2.

3 cases:

  1. Wifi enabled + AndroidSettings foregroundNotification enabled: everything works fine

  2. Wifi disabled + AndroidSettings foregroundNotification disabled: message about enabling Wifi scanning shows (see screenshot above by @thedeukalion ). After activating Wifi scanning, everything works fine. This is the intended behavior.

  3. Wifi disabled + AndroidSettings foregroundNotification enabled: No message about enabling Wifi scanning shows. Calling Geolocator.getPositionStreams throws error that location service is disabled, although location service is enabled and Geolocator.isLocationServiceEnabled returns true.

Case 3 is the critical one -> disabling Wifi with foregroundNotification enabled makes Geolocator stop working without any prompt to the user to activate Wifi scanning. Could you fix that issue and make the Wifi-scan-prompt show also if foregroundNotification is enabled? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. status: needs more info We need more information before we can continue work on this issue.
Projects
None yet
Development

No branches or pull requests

3 participants