content: package com.afei.camera2getpreview.util;
  
  import android.Manifest;
  import android.app.Activity;
  import android.content.pm.PackageManager;
  import android.os.Build;
  
  import androidx.core.app.ActivityCompat;
  import androidx.core.content.ContextCompat;
  
  public class Permission {
  
      public static final int REQUEST_CODE = 5;
  
      private static final String[] PERMISSIONS = new String[]{
              Manifest.permission.CAMERA,
              Manifest.permission.WRITE_EXTERNAL_STORAGE,
      };
  
      public static boolean checkPermission(Activity activity) {
          if (isPermissionGranted(activity)) {
              return true;
          } else {
              ActivityCompat.requestPermissions(activity, PERMISSIONS, REQUEST_CODE);
              return false;
          }
      }
  
      public static boolean isPermissionGranted(Activity activity) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
              for (int i = 0; i < PERMISSIONS.length; i++) {
                  int checkPermission = ContextCompat.checkSelfPermission(activity, PERMISSIONS[i]);
                  if (checkPermission != PackageManager.PERMISSION_GRANTED) {
                      return false;
                  }
              }
          }
          return true;
      }
  }
  