mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 20:44:10 +00:00
Better error handling in Android Geolocation module (PR 2)
Summary: Just a testing PR for the shipit bot (please don't close :)) Closes https://github.com/facebook/react-native/pull/4355 Reviewed By: svcscm Differential Revision: D2702784 Pulled By: mkonicek fb-gh-sync-id: 867c65dcea486750ca65a8437b37a0f658538111
This commit is contained in:
parent
3dca8cf9fd
commit
c9dd4015f1
@ -107,28 +107,25 @@ public class LocationModule extends ReactContextBaseJavaModule {
|
|||||||
Callback error) {
|
Callback error) {
|
||||||
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
|
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
|
||||||
|
|
||||||
LocationManager locationManager =
|
|
||||||
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
|
||||||
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
|
||||||
if (provider == null) {
|
|
||||||
error.invoke("No available location provider.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location location = null;
|
|
||||||
try {
|
try {
|
||||||
location = locationManager.getLastKnownLocation(provider);
|
LocationManager locationManager =
|
||||||
|
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
||||||
|
if (provider == null) {
|
||||||
|
error.invoke("No available location provider.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Location location = locationManager.getLastKnownLocation(provider);
|
||||||
|
if (location != null &&
|
||||||
|
SystemClock.currentTimeMillis() - location.getTime() < locationOptions.maximumAge) {
|
||||||
|
success.invoke(locationToMap(location));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
|
||||||
|
.invoke();
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
throwLocationPermissionMissing(e);
|
throwLocationPermissionMissing(e);
|
||||||
}
|
}
|
||||||
if (location != null &&
|
|
||||||
SystemClock.currentTimeMillis() - location.getTime() < locationOptions.maximumAge) {
|
|
||||||
success.invoke(locationToMap(location));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
|
|
||||||
.invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,24 +140,23 @@ public class LocationModule extends ReactContextBaseJavaModule {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
|
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
|
||||||
LocationManager locationManager =
|
|
||||||
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
|
||||||
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
|
||||||
if (provider == null) {
|
|
||||||
emitError("No location provider available.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
LocationManager locationManager =
|
||||||
|
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
||||||
|
if (provider == null) {
|
||||||
|
emitError("No location provider available.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!provider.equals(mWatchedProvider)) {
|
if (!provider.equals(mWatchedProvider)) {
|
||||||
locationManager.removeUpdates(mLocationListener);
|
locationManager.removeUpdates(mLocationListener);
|
||||||
locationManager.requestLocationUpdates(provider, 1000, 0, mLocationListener);
|
locationManager.requestLocationUpdates(provider, 1000, 0, mLocationListener);
|
||||||
}
|
}
|
||||||
|
mWatchedProvider = provider;
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
throwLocationPermissionMissing(e);
|
throwLocationPermissionMissing(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
mWatchedProvider = provider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user