Created
June 8, 2019 18:07
-
-
Save sirmordred/70c0dd554f1fa1442765ab42a1a7f27c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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