Skip to content

Instantly share code, notes, and snippets.

@dvas0004
Created May 13, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvas0004/1c123ef5988260e0a925eea79f9c2806 to your computer and use it in GitHub Desktop.
Save dvas0004/1c123ef5988260e0a925eea79f9c2806 to your computer and use it in GitHub Desktop.
mLayout = findViewById(R.id.fullscreen_content);
if (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.CAMERA)
!= 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() {
@Override
public void onClick(View view) {
// Request the permission
ActivityCompat.requestPermissions(FullscreenActivity.this,
new String[]{android.Manifest.permission.CAMERA},
159);
}
}).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions((Activity)mContext,
new String[]{android.Manifest.permission.CAMERA},
159);
// 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