Skip to content

Instantly share code, notes, and snippets.

@techwizrd
Last active October 9, 2016 02:52
Show Gist options
  • Save techwizrd/f23539e43d5920a77ac10ddaa570172d to your computer and use it in GitHub Desktop.
Save techwizrd/f23539e43d5920a77ac10ddaa570172d to your computer and use it in GitHub Desktop.
Access fine location Android
private boolean hasLocationPermissions() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManger.PERMISSION_GRANTED;
}
private void requestLocationPermission() {
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION) {
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION});
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!this.hasLocationPermissions()) {
this.requestLocationPermission();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment