Skip to content

Commit cf839a0

Browse files
authored
Check LocationSettingsResponse success before processing (#1730)
First check if the `LocationSettingsResponse` task was successful before attempting to get the result.
1 parent ce4b3a7 commit cf839a0

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

geolocator_android/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## NEXT
22

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

56
## 5.0.1+1
67

geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ public void isLocationServiceEnabled(LocationServiceListener listener) {
167167
(response) -> {
168168
if (!response.isSuccessful()) {
169169
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
170-
}
171-
172-
LocationSettingsResponse lsr = response.getResult();
173-
if (lsr != null) {
174-
LocationSettingsStates settingsStates = lsr.getLocationSettingsStates();
175-
boolean isGpsUsable = settingsStates != null && settingsStates.isGpsUsable();
176-
boolean isNetworkUsable =
177-
settingsStates != null && settingsStates.isNetworkLocationUsable();
178-
listener.onLocationServiceResult(isGpsUsable || isNetworkUsable);
179170
} else {
180-
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
171+
LocationSettingsResponse lsr = response.getResult();
172+
if (lsr != null) {
173+
LocationSettingsStates settingsStates = lsr.getLocationSettingsStates();
174+
boolean isGpsUsable = settingsStates != null && settingsStates.isGpsUsable();
175+
boolean isNetworkUsable =
176+
settingsStates != null && settingsStates.isNetworkLocationUsable();
177+
listener.onLocationServiceResult(isGpsUsable || isNetworkUsable);
178+
} else {
179+
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
180+
}
181181
}
182182
});
183183
}

0 commit comments

Comments
 (0)