PermissionUtils.java 965 B

1234567891011121314151617181920212223242526272829303132333435
  1. package com.slam.bboxble;
  2. import android.content.pm.PackageManager;
  3. /**
  4. * Utility class that wraps access to the runtime permissions API in M and provides basic helper
  5. * methods.
  6. */
  7. public abstract class PermissionUtils {
  8. /**
  9. * Check that all given permissions have been granted by verifying that each entry in the
  10. * given array is of the value {@link PackageManager#PERMISSION_GRANTED}.
  11. *
  12. * @see Activity#onRequestPermissionsResult(int, String[], int[])
  13. */
  14. public static boolean verifyPermissions(int[] grantResults) {
  15. // At least one result must be checked.
  16. if (grantResults.length < 1) {
  17. return false;
  18. }
  19. // Verify that each required permission has been granted, otherwise return false.
  20. for (int result : grantResults) {
  21. if (result != PackageManager.PERMISSION_GRANTED) {
  22. return false;
  23. }
  24. }
  25. return true;
  26. }
  27. }