【Blackberry】权限申请

阅读更多

Blackberry引导系统权限页面申请权限 os 5,6,7下都是适用的

 

 

public class PermissionApply {

	private static int[] permissions = {
			ApplicationPermissions.PERMISSION_FILE_API,
			ApplicationPermissions.PERMISSION_RECORDING};

	/**
	 * 判断当前应用是否有 某个权限
	 * 
	 */
	public static boolean couldCapture(int permission) {
		ApplicationPermissions apm = ApplicationPermissionsManager
				.getInstance().getApplicationPermissions();
		return apm.getPermission(permission) == ApplicationPermissions.VALUE_ALLOW;
	}

	/**
	 * 
	 * @Title: setupPermissions
	 * @Description: 如没有指定权限,则申请权限(程序启动时候调用)
	 * @return boolean true: 已经获取权限,false:没有权限
	 * @throws
	 */
	public static boolean setupPermissions() {
		ApplicationPermissionsManager man = ApplicationPermissionsManager
				.getInstance();
		ApplicationPermissions perms = new ApplicationPermissions();
		boolean change = false;
		for (int i = 0; i < permissions.length; i++) {
			if (man.getPermission(permissions[i]) != ApplicationPermissions.VALUE_ALLOW) {
				change = true;
				perms.addPermission(permissions[i]);
			}
		}
		if (change) {
			return man.invokePermissionsRequest(perms);
		} else {
			return true;
		}
	}
}

你可能感兴趣的:(【Blackberry】权限申请)