Skip to content

Instantly share code, notes, and snippets.

@sirmordred
Created June 8, 2019 18:07
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 sirmordred/70c0dd554f1fa1442765ab42a1a7f27c to your computer and use it in GitHub Desktop.
Save sirmordred/70c0dd554f1fa1442765ab42a1a7f27c to your computer and use it in GitHub Desktop.
private boolean checkPermission() {
return ContextCompat.checkSelfPermission(MainActivity.this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.
PERMISSION_GRANTED;
}
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(MainActivity.this, "Write External Storage permission allows us to " +
"do store rescue package. Please allow this permission in App Settings.",
Toast.LENGTH_LONG).show();
showOneTimeAd();
} else {
Toast.makeText(MainActivity.this, "Write External Storage permission allows us to " +
"do store rescue package. Please allow this permission",
Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "Permission Granted, Now you can copy rescue package .");
} else {
Log.i(TAG, "Permission Denied, You cannot copy rescue package .");
Toast.makeText(ctx,"Failed, Rescue package cannot be copied, " +
"You should grant required permission",Toast.LENGTH_LONG).show();
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment