Created
July 24, 2020 19:22
-
-
Save vladimirpetrovski/14b6c6160aa5f7042537bb69a81e772d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| fun checkLocationSettings(onSuccessCallback: () -> Unit) { | |
| val locationRequest = LocationRequest.create() | |
| locationRequest.priority = LocationRequest.PRIORITY_LOW_POWER | |
| val builder = LocationSettingsRequest.Builder() | |
| builder.addLocationRequest(locationRequest) | |
| val client = LocationServices.getSettingsClient(this) | |
| val task = client.checkLocationSettings(builder.build()) | |
| task.addOnSuccessListener(this) { | |
| onSuccessCallback() | |
| } | |
| task.addOnFailureListener(this) { | |
| if (it is ResolvableApiException) { | |
| // Location settings are not satisfied, but this can be fixed | |
| // by showing the user a dialog. | |
| try { | |
| // Show the dialog by calling startResolutionForResult(), | |
| // and check the result in onActivityResult(). | |
| it.startResolutionForResult(this, 111) | |
| } catch (sendEx: IntentSender.SendIntentException) { | |
| // Ignore the error. | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment