Skip to content

Instantly share code, notes, and snippets.

@LiorA1
Created May 11, 2020 20:47
Show Gist options
  • Save LiorA1/7552c136bc29c6f0fd6a84804f60c5f9 to your computer and use it in GitHub Desktop.
Save LiorA1/7552c136bc29c6f0fd6a84804f60c5f9 to your computer and use it in GitHub Desktop.
isPermissionGranted basic example
public boolean isPermissionGranted()
{
boolean res = false;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
/*&& ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED*/)
{
res = true;
}
// Else ask for permission
else
{
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
/*Manifest.permission.RECORD_AUDIO*/},
0);
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment