Skip to content

Instantly share code, notes, and snippets.

@bhrott
Created November 16, 2016 11:53
Show Gist options
  • Save bhrott/41ac7908bf4346c3f0579206b54b66b8 to your computer and use it in GitHub Desktop.
Save bhrott/41ac7908bf4346c3f0579206b54b66b8 to your computer and use it in GitHub Desktop.
React Native : Android : Check Location Enable State
@ReactMethod
public void isLocationEnabled(Promise promise) {
try {
Boolean permissionIsGranted = ContextCompat.checkSelfPermission( getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED;
final LocationManager manager = (LocationManager) getReactApplicationContext().getSystemService( Context.LOCATION_SERVICE );
Boolean gpsIsEnabled = manager.isProviderEnabled( LocationManager.GPS_PROVIDER );
Boolean isEnabled = permissionIsGranted && gpsIsEnabled;
promise.resolve(isEnabled);
}catch (Exception e) {
promise.reject(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment