// Get the ActivityGroupService.
ActivityGroupServiceInterface activityGroupService =
dfpServices.get(session, ActivityGroupServiceInterface.class);
// Get the activity group.
ActivityGroup activityGroup = activityGroupService.getActivityGroup(activityGroupId);
// Update the companies.
activityGroup.setCompanyIds(
Longs.concat(activityGroup.getCompanyIds(), new long[] {advertiserCompanyId}));
// Update the activity group on the server.
ActivityGroup[] activityGroups =
activityGroupService.updateActivityGroups(new ActivityGroup[] {activityGroup});