diff --git a/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java b/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java index 1cfcf88..5de2983 100644 --- a/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java +++ b/android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java @@ -62,27 +62,57 @@ public class RNFusedLocationModule extends ReactContextBaseJavaModule { @Override public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) { if (requestCode == REQUEST_SETTINGS_SINGLE_UPDATE) { - if (resultCode == Activity.RESULT_OK || mForceRequestLocation) { + if (resultCode == Activity.RESULT_OK) { // Location settings changed successfully, request user location. getUserLocation(); - } else if (resultCode == Activity.RESULT_CANCELED) { + return; + } + + if (!mForceRequestLocation) { invokeError( LocationError.SETTINGS_NOT_SATISFIED.getValue(), "Location settings are not satisfied.", true ); + return; + } + + if (!LocationUtils.isLocationEnabled(getContext())) { + invokeError( + LocationError.POSITION_UNAVAILABLE.getValue(), + "No location provider available.", + true + ); + return; } + + getUserLocation(); } else if (requestCode == REQUEST_SETTINGS_CONTINUOUS_UPDATE) { - if (resultCode == Activity.RESULT_OK || mForceRequestLocation) { + if (resultCode == Activity.RESULT_OK ) { // Location settings changed successfully, request user location. getLocationUpdates(); - } else if (resultCode == Activity.RESULT_CANCELED) { + return; + } + + if (!mForceRequestLocation) { invokeError( LocationError.SETTINGS_NOT_SATISFIED.getValue(), "Location settings are not satisfied.", false ); + return; } + + if (!LocationUtils.isLocationEnabled(getContext())) { + invokeError( + LocationError.POSITION_UNAVAILABLE.getValue(), + "No location provider available.", + false + ); + return; + } + + getLocationUpdates(); } } }; @@ -127,15 +157,6 @@ public void getCurrentPosition(ReadableMap options, final Callback success, fina return; } - if (!LocationUtils.isLocationEnabled(context)) { - invokeError( - LocationError.POSITION_UNAVAILABLE.getValue(), - "No location provider available.", - true - ); - return; - } - if (!LocationUtils.isGooglePlayServicesAvailable(context)) { invokeError( LocationError.PLAY_SERVICE_NOT_AVAILABLE.getValue(),