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

Enhancement/1366-prevent-crash-form-happening #1367

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.4.1

- Adds addOnFailureListener to getSettingsClient to prevent crashes.

## 4.4.0

- Adds `color` to `ForegroundNotificationConfig` to set the color of the notification icon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum ErrorCodes {
activityMissing,
errorWhileAcquiringPosition,
locationServicesDisabled,
locationServicesFailed,
permissionDefinitionsNotFound,
permissionDenied,
permissionRequestInProgress;
Expand All @@ -16,6 +17,8 @@ public String toString() {
return "ERROR_WHILE_ACQUIRING_POSITION";
case locationServicesDisabled:
return "LOCATION_SERVICES_DISABLED";
case locationServicesFailed:
return "LOCATION_SERVICES_FAILED";
case permissionDefinitionsNotFound:
return "PERMISSION_DEFINITIONS_NOT_FOUND";
case permissionDenied:
Expand All @@ -35,6 +38,8 @@ public String toDescription() {
return "An unexpected error occurred while trying to acquire the device's position.";
case locationServicesDisabled:
return "Location services are disabled. To receive location updates the location services should be enabled.";
case locationServicesFailed:
return "Location services failed.";
case permissionDefinitionsNotFound:
return "No location permissions are defined in the manifest. Make sure at least ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION are defined in the manifest.";
case permissionDenied:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.android.gms.location.LocationSettingsStatusCodes;
import com.google.android.gms.location.Priority;
import com.google.android.gms.location.SettingsClient;
import com.google.android.gms.tasks.OnFailureListener;

import java.security.SecureRandom;

Expand Down Expand Up @@ -168,6 +169,13 @@ public void isLocationServiceEnabled(LocationServiceListener listener) {
} else {
listener.onLocationServiceError(ErrorCodes.locationServicesDisabled);
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
listener.onLocationServiceError(ErrorCodes.locationServicesFailed);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public static Map<String, Object> toHashMap(Location location) {

if (location.hasAltitude()) position.put("altitude", location.getAltitude());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasVerticalAccuracy())
position.put("altitude_accuracy", location.getVerticalAccuracyMeters());
position.put("altitude_accuracy", location.getVerticalAccuracyMeters());
if (location.hasAccuracy()) position.put("accuracy", (double) location.getAccuracy());
if (location.hasBearing()) position.put("heading", (double) location.getBearing());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasBearingAccuracy())
position.put("heading_accuracy", location.getBearingAccuracyDegrees());
position.put("heading_accuracy", location.getBearingAccuracyDegrees());
if (location.hasSpeed()) position.put("speed", (double) location.getSpeed());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasSpeedAccuracy())
position.put("speed_accuracy", (double) location.getSpeedAccuracyMetersPerSecond());
Expand Down
2 changes: 1 addition & 1 deletion geolocator_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: geolocator_android
description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
version: 4.4.0
version: 4.4.1

environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down