Menu

Create custom agent

The Samsung EDU SDK enables developers to create their own custom agent based on their needs and can add it to the AgentManager. An agent commands range for the provided eleven agents of the EDU SDK (range of 0 – 359). Each agent has a command base starting from the Agent ID to the next thirty numbers. Agent ID and command base is a unique integer for each agent as they have been added to a common AgentManager. Each agent is added using their command list, or minimum and maximum command values based on agent constants.

Steps to create a custom agent

A new custom agent (default agent) should extend BaseAgent and implement the following API methods:

  • created [protected / final] — This is called when BaseAgent is created and added successfully to AgentManager.
  • onInitialized [protected / abstract] — This is called after adding AgentManager. Using this API method, all the initializing is done.
  • onSessionStarted [protected / final] — This is called when session is started successfully. The Agent registers itself to User State Notifier, which is created by SessionManageAgent and passed from agent mediator. Using User State Notifier, the agent listens to the user's change of state.
  • onStarted [protected / abstract] — This is called at the end of onSessionStarted to inform each agent.
  • onSessionStopped [protected / final] — This is called when session is stopped. The agent stops receiving callback from User State Changed Listener.
  • onStopped [protected / abstract] — This is called at the end of onSessionStopped to inform each agent. When user leaves or stops session, this API is called.
  • onUpdate [protected / abstract] — This is called when data or message is arrived, and if it is an expected one. This API method dispatches the data to the respective agent.
  • onDisconnected [protected / abstract] — This is called when device is disconnected from the network.
  • onReconnected [protected / abstract] — This is called when device is reconnected to the network.
  • sendData [protected] — This is called to send data to other participants in the session.
/** create a Sample agent **/
private DefaultAgent defaultAgent;

/** Create an Instance of Agent Manager **/
agentManager = AgentManager.createInstance(mContext);

/** Add agent to agent Manager **/
agentManager.addAgent(DefaultAgent.AGENT_ID, DefaultAgent.AGENT_CMD_MAX, DefaultAgent.class);

/** In above, AGENT_ID starts from AgentConstants. USER_AGENT_START_ID for User created agents.
      AGENT_CMD_MAX will be AGENT_ID + AgentConstants.NUMBER_OF_COUNT -1 **/

/** Get Agent from Agent Manager **/
defaultAgent = (DefaultAgent) agentManager.getAgent(DefaultAgent.class);