Skip to content

Instantly share code, notes, and snippets.

Created May 13, 2016 14:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
mLayout = findViewById(;
if (ContextCompat.checkSelfPermission(mContext,
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext,
android.Manifest.permission.CAMERA)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Snackbar.make(mLayout, "Camera access is required to attach pictures to tasks.",
Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() {
public void onClick(View view) {
// Request the permission
new String[]{android.Manifest.permission.CAMERA},
} else {
// No explanation needed, we can request the permission.
new String[]{android.Manifest.permission.CAMERA},
// 159 is an app-defined int constant. The callback method gets the
// result of the request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment