Skip to content

Instantly share code, notes, and snippets.

@kanta1311
Created March 9, 2018 10:30
Show Gist options
  • Save kanta1311/5d4acfe01d4a2852d359d7a19ec8a9b9 to your computer and use it in GitHub Desktop.
Save kanta1311/5d4acfe01d4a2852d359d7a19ec8a9b9 to your computer and use it in GitHub Desktop.
Camera Permission Android
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
takePictureButton.setEnabled(false);
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 0) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
takePictureButton.setEnabled(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment