package com.steps.tmuapp.lib;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class VersionUtils {
    /**
     * 6.0 手机系统以上 检查并请求权限
     * @param activity 必须为 Activity
     */
    public static boolean checkAndRequestCameraPermissionAbove23(Activity activity){
        if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED
                || ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED
        ){
            ActivityCompat.requestPermissions(activity,
                    Permissions.FILE_UPLOAD_PERMISSIONS, Permissions.REQUEST_EXTERNAL_STORAGE_PERMISSION
            );
            return ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    == PackageManager.PERMISSION_GRANTED &&
                    ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA)
                            == PackageManager.PERMISSION_GRANTED;
        }else{
            return  true;
        }
    }
}
