Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. private boolean checkPermission() {
  2. return ContextCompat.checkSelfPermission(MainActivity.this,
  3. android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.
  4. PERMISSION_GRANTED;
  5. }
  6.  
  7. private void requestPermission() {
  8. if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
  9. android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
  10. Toast.makeText(MainActivity.this, "Write External Storage permission allows us to " +
  11. "do store rescue package. Please allow this permission in App Settings.",
  12. Toast.LENGTH_LONG).show();
  13. showOneTimeAd();
  14. } else {
  15. Toast.makeText(MainActivity.this, "Write External Storage permission allows us to " +
  16. "do store rescue package. Please allow this permission",
  17. Toast.LENGTH_LONG).show();
  18. ActivityCompat.requestPermissions(MainActivity.this,
  19. new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
  20. PERMISSION_REQUEST_CODE);
  21. }
  22. }
  23.  
  24. @Override
  25. public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
  26. switch (requestCode) {
  27. case PERMISSION_REQUEST_CODE:
  28. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  29. Log.i(TAG, "Permission Granted, Now you can copy rescue package .");
  30. } else {
  31. Log.i(TAG, "Permission Denied, You cannot copy rescue package .");
  32. Toast.makeText(ctx,"Failed, Rescue package cannot be copied, " +
  33. "You should grant required permission",Toast.LENGTH_LONG).show();
  34. }
  35. break;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement