Created
November 16, 2016 11:53
-
-
Save bhrott/41ac7908bf4346c3f0579206b54b66b8 to your computer and use it in GitHub Desktop.
React Native : Android : Check Location Enable State
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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