Guest User

Untitled

a guest
Jan 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. @Override
  2. public void onResume()
  3. {
  4. super.onResume();
  5.  
  6. if (!HasCameraPermission())
  7. {
  8. RequestCameraPermission();
  9.  
  10. return;
  11. }
  12. }
  13.  
  14. @Override
  15. public void onRequestPermissionsResult(int _RequestCode, String[] _Permissions, int[] _Results)
  16. {
  17. if (!HasCameraPermission())
  18. {
  19. Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG).show();
  20.  
  21. if (!ShouldShowRequestPermissionRationale())
  22. {
  23. // Permission denied checking "Do not ask again".
  24. LaunchPermissionSettings();
  25. }
  26.  
  27. finish();
  28. }
  29. }
  30.  
  31. public boolean HasCameraPermission()
  32. {
  33. return this.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
  34. }
  35.  
  36. public void RequestCameraPermission()
  37. {
  38. this.requestPermissions(new String[] {Manifest.permission.CAMERA}, 0);
  39. }
  40.  
  41. public boolean ShouldShowRequestPermissionRationale()
  42. {
  43. return this.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA);
  44. }
  45.  
  46. public void LaunchPermissionSettings()
  47. {
  48. Intent intent = new Intent();
  49. intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  50. intent.setData(Uri.fromParts("package", this.getPackageName(), null));
  51.  
  52. this.startActivity(intent);
  53. }
Add Comment
Please, Sign In to add comment