...
- Open the Android agent source code in Android studio.
The event related logic is included in theorg.wso2.emm.agent.events
package. It has the following folder structure.
[image of project structure to be added here] Implement the
AlertEventListener
interface in theorg.wso2.emm.agent.events.listeners
package.Info Expand title Click here for more information on the methods used in the AlertEventListener interface. The following methods are used:
startListening()
- This method is used to start listening to an event broadcasted by the OS. In case of a polling based check, this method can be called by the onReceive method of the AlarmReceiver.stopListening()
- Stop a receiver or an alarm can be done herepublishEvent(String payload)
- Publishing data to EMM can be handled here.
Example:
Code Block language java title AlertEventListener interface firstline 1 linenumbers true package org.wso2.emm.agent.events.listeners; /** * This is used to define any new events that needs to be captured and sent to server. */ public interface AlertEventListener { /** * This can be used to start listening to a specific broadcast receiver. * Another usage would be, when there is an event that doesn't do a broadcast. For example * Application exceeding 75% of CPU is not broadcasted by default from the Android OS. Only way * to catch it is by constantly polling a specific API and check for the status. In such a * situation, AlarmManager can call startListening on it onReceiver method to do the polling on * an API. */ void startListening(); /** * If in case, listening to a specific receiver need to be done here. This can be a place to, * stop an AlarmManager. */ void stopListening(); /** * This is where publishing data to EMM/DAS would happen. This can ideally be called from * an onReceive method of a BroadcastReceiver, or from startListening method to inform the * results of a polling. * * @param payload JSON string payload to be published. * @param type type of the alert being published. */ void publishEvent(String payload, String type); }
- Capturing events. There are two ways to capture the events as listed below:
Panel borderColor #11375B bgColor #ffffff borderWidth 1 Include Page Listening to events broadcasted by the Android OS Listening to events broadcasted by the Android OS Localtab title Events not broadcastedListen to events broadcasted by the Android OS.
Info For more information, see Listening to events broadcasted by the Android OS.
Poll an API to check for event changes that are not broadcasted continuously by the Android OS.
Localtabgroup Localtab title Events broadcasted by the Android OS Info For more information. see Listen to Events Not Broadcasted by the Android OS.