diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/location/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/location/BUCK index 37df1e9b950d93..8ba313dee7add3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/location/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/location/BUCK @@ -8,6 +8,7 @@ rn_android_library( ], deps = [ react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"), + react_native_dep("third-party/android/support/v4:lib-support-v4"), react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_target("java/com/facebook/react/bridge:bridge"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java index 22d6b9f405ee36..520eb2947a1b1c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java @@ -9,6 +9,7 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; @@ -16,6 +17,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.support.v4.content.ContextCompat; import com.facebook.common.logging.FLog; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; @@ -193,7 +195,7 @@ public void stopObserving() { } @Nullable - private static String getValidProvider(LocationManager locationManager, boolean highAccuracy) { + private String getValidProvider(LocationManager locationManager, boolean highAccuracy) { String provider = highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { @@ -204,6 +206,11 @@ private static String getValidProvider(LocationManager locationManager, boolean return null; } } + // If it's an enabled provider, but we don't have permissions, ignore it + int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION); + if (provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) { + return null; + } return provider; }