diff --git a/geolocator_android/CHANGELOG.md b/geolocator_android/CHANGELOG.md index e5a5f7e2d..4d18cadca 100644 --- a/geolocator_android/CHANGELOG.md +++ b/geolocator_android/CHANGELOG.md @@ -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 diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java index a5e3f2b13..bef3090c6 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java @@ -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); + } } }); }