protected void enableLocationSettings() {
LocationRequest locationRequest = LocationRequest.create()
.setInterval(10 * 1000)
.setFastestInterval(2 * 1000)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
LocationServices
.getSettingsClient(requireActivity())
.checkLocationSettings(builder.build())
.addOnSuccessListener(requireActivity(), (LocationSettingsResponse response) -> {
// startUpdatingLocation(...);
})
.addOnFailureListener(requireActivity(), ex -> {
if (ex instanceof ResolvableApiException) {
try{
IntentSenderRequest intentSenderRequest = new IntentSenderRequest.Builder(((ResolvableApiException) ex).getResolution()).build();
resolutionForResult.launch(intentSenderRequest);
}catch (Exception exception){
Log.d(TAG, "enableLocationSettings: "+exception);
}
}
});
}