Skip to content

Instantly share code, notes, and snippets.

@AlexGladkov
Created August 4, 2017 08:32
Show Gist options
  • Save AlexGladkov/944cf2b7161b2e8b894a08ace5d46a18 to your computer and use it in GitHub Desktop.
Save AlexGladkov/944cf2b7161b2e8b894a08ace5d46a18 to your computer and use it in GitHub Desktop.
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case LOCATION_REQUEST: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
viewModel.setLocationState(ComposeViewModel.LOCATION_ON);
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(mActivity);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
mFusedLocationClient.getLastLocation().addOnCompleteListener(mActivity, new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
currentLocation = task.getResult();
viewModel.addLocation(task.getResult());
}
});
} else {
viewModel.setLocationState(ComposeViewModel.LOCATION_DISABLED);
}
return;
}
case PHOTO_REQUEST: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment