Java tutorial
//package com.java2s; //License from project: Apache License import android.Manifest; import android.content.Context; import android.os.Binder; import android.util.Log; public class Main { private static final String TAG = "PermissionUtil"; public static final String[] PERMISSIONS_GROUP_CAMERA = { Manifest.permission.CAMERA, "android.hardware.camera", "android.hardware.camera.autofocus" }; public static boolean checkCamera(Context context) { return check(context, PERMISSIONS_GROUP_CAMERA); } public static boolean check(Context context, String... premissions) { try { if (null == context) throw new RuntimeException("Context is null."); for (int i = 0; i < premissions.length; i++) { Integer check = context.checkPermission(premissions[i], Binder.getCallingPid(), Binder.getCallingUid()); if (check == -1) { return false; } } return true; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); return false; } } public static boolean check(Context context, String[]... permissionsBase) { for (int i = 0; i < permissionsBase.length; i++) { String[] permissions = permissionsBase[i]; boolean isCheck = check(context, permissions); if (isCheck == false) { return false; } } return true; } }