Skip to content

Check LocationSettingsResponse success before processing #1730

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

- Fixes PlatformException in example app for Android 14 (API level 34) versions and newer by updating manifest permissions.
- Prevented crash by checking `isSuccessful` before calling `getResult()` in location settings check.

## 5.0.1+1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ public void isLocationServiceEnabled(LocationServiceListener listener) {
(response) -> {
if (!response.isSuccessful()) {
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
}

LocationSettingsResponse lsr = response.getResult();
if (lsr != null) {
LocationSettingsStates settingsStates = lsr.getLocationSettingsStates();
boolean isGpsUsable = settingsStates != null && settingsStates.isGpsUsable();
boolean isNetworkUsable =
settingsStates != null && settingsStates.isNetworkLocationUsable();
listener.onLocationServiceResult(isGpsUsable || isNetworkUsable);
} else {
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
LocationSettingsResponse lsr = response.getResult();
if (lsr != null) {
LocationSettingsStates settingsStates = lsr.getLocationSettingsStates();
boolean isGpsUsable = settingsStates != null && settingsStates.isGpsUsable();
boolean isNetworkUsable =
settingsStates != null && settingsStates.isNetworkLocationUsable();
listener.onLocationServiceResult(isGpsUsable || isNetworkUsable);
} else {
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
}
}
});
}
Expand Down