Creates the instance of HCE Session class.
NOTE!!!: Do not use this constructor directly. Use getInstance to get the appropriate and synchronized instance.
The current subject application to emulate in HCE.
NOTE: Do not set the current application by assigning to this property. Use the setApplication instead.
Is the HCE Service currently enabled and visible to OS.
NOTE: Do not set the current state by assigning to this property. Use the setEnabled instead.
Static
EventsObject that contains the events that the application can listen to using HCESession.on(...)
.
Check the HCESessionEvents interface to get the listing of availble events.
Usage of the property in event listener:
hceSession.on(HCESession.Events.HCE_CONNECTED)
Adds event listener to the HCE Session.
Returns the reference to "stop listening" method. To stop listening the event, just call it.
import { ToastAndroid } from "react-native"
import { HCESession } from "react-native-hce"
...
const instance = await HCESession.getInstance();
const removeListener = instance.on(HCESession.Events.HCE_STATE_READ, () => {
ToastAndroid.show("The tag has been read! Thank You.", ToastAndroid.LONG);
removeListener();
};
The event that application should listen to. You should pass the constant from static Events property. If null, the listener will respond to all events - that can be usable for logging purposes.
The event listener.
Update the subject application to emulate in HCE.
The application to set, must be instance of HCEApplication.
Toggle the state of HCE service.
This function allows to enable or disable the native component of HCE Service. If enabled, the native HostApduService will be recognizable by platform's HCE router. If not, service won't be recognized, thus all the interactions between HCE and reader won't be available.
NOTE: Before switching the service on, use the setApplication first to register the content that You want to emulate using HCE.
True to enable the service, false to disable.
Static
getGets the instance of HCE Session.
As there is only one HCE Session per application available, use this function to get the instance instead of using the constructor.
Generated using TypeDoc
Class for the session state management.
HCESession is an entry point for the react-native-hce library. This class manages the entire connection with native counterparts managing the HCE emulation.
You should use only one instance of the class should be used per application. That's why we created it with the intention of use as a singleton. To get the instance, use the getInstance static method that will get a current instance and will do the synchronization with native for You.