Skip to content

Instantly share code, notes, and snippets.

@spidergears
Last active July 14, 2016 20:05
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 spidergears/9a34f0ffcdadb964e2b0f402d245e966 to your computer and use it in GitHub Desktop.
Save spidergears/9a34f0ffcdadb964e2b0f402d245e966 to your computer and use it in GitHub Desktop.
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
captureImage();
else{
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE))
showRationaleDialog();
else
Toast.makeText(MainActivity.this, "You need to allow permission to Write to External Storage", Toast.LENGTH_LONG).show();
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
private void showRationaleDialog(){
new AlertDialog.Builder(MainActivity.this)
.setMessage("Application needs access to READ/WRITE LocalStorage to store images.")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
requestPermissionWriteToLocalStorage();
}
})
.setNegativeButton("Cancel", null)
.create()
.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment