Hardware Listner is one of Infairy broadcast channel which can get some event from the tablet or hardware.
Developer can listen Hardware broadcast channel to get from the tablet of Infairy which hosted machine, such as when user touch the screen.
please follow the step as below:
First, import package as follows:
Developer can listen Hardware broadcast channel to get from the tablet of Infairy which hosted machine, such as when user touch the screen.
please follow the step as below:
import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; import com.infairy.cocina.SDK.gene.EventHardwareDNA;then, implement "EventHandler" in your bundle class:
package yourBundle; public class CommData implements BundleActivator, EventHandler{ .... }Third, implement HandleEvent() method,
public void handleEvent(Event evnt) { ... }Last, do not forget listen SENSOR broadcast channel in start() method, because the hardware is a dna object,
package yourBundle; public class CommData implements BundleActivator, EventHandler{ .... public void start(BundleContext context) throws Exception { ... device.ListenBroadcast(context, this, device.BROADCAST_CHANNEL_SENSOR); } }after done the process as above, you can get the data from all RXTX channel, but not every data is yours, so you have to filter the data by "RXTX_Device_Name", and then, check the data checksum value if it is necessary.
public void handleEvent(Event evnt) { if(evnt==null) return; //cast EventHardwareDNA from event property "BROADCAST_HARDWARE_TRIGGER_EVENTOBJECT" EventHardwareDNA EHD = (EventHardwareDNA)evnt.getProperty(device.BROADCAST_HARDWARE_TRIGGER_EVENTOBJECT); if(EHD==null) return; if(EHD.Type.equals("")) return; String TYPE=EHD.Type; if(TYPE.equals("")) return; if(TYPE.equals(device.BROADCAST_APP_GUESTURE_INDEX)){ //user guesture ;// do something } if(TYPE.equals(device.BROADCAST_MANUAL_OP)){ //user clicked ;//do something } }The EventHardwareDNA interface shows as below:
/** * Hardware changed: */ public String Value=""; /** * Hardware changed: type, we now defined two type of hardware event: * BROADCAST_APP_GUESTURE_INDEX : Users guesture * BROADCAST_MANUAL_OP : User clicked */ public String Type="";