HCE_STATE_READ event is fired multiple times on tag reading
I'm trying to emulate a NFCtagType4 with an Android device. I'm able to read the tag but HCE_STATE_READ event is fired 3 times. Is that the desired behaviour? I fixed it locally in respondRead method inside NFCTagType4 class:
if (realLength == slicedResponse.length) {
this.hceModel.getLastState()
.setValue(HceViewModel.HCE_STATE_READ);
}
Could it be a valid solution to avoid multiple firings?
Same here, it keeps bumping up and the only way to fix it is to close the app to reset the session . . even if the component is unmount and re-mount it triggers a lot
any solution on how to fix this?
let removeListener = session.on(HCESession.Events.HCE_STATE_READ, async () => {
Alert.alert(
'Success',
`NFC connection successfully completed.`,
[{text: 'Ok', onPress: async () => {
}}]
);
});
removeListener();
listener is not removed even if the component is unmounted . .
This is still an issue as of July 2025.
Edit: I have found a temporary fix:
listener = session.addListener("hceState", (eventData) => {
console.log("HCE State Changed:", eventData);
});
...
listener.remove();
After adding debug logs to the onChanged function in EventManager.java, I verified that events are being emitted correctly to the React Native bridge. However, I noticed that the .on() implementation in the JavaScript layer triggers multiple times for the same event (specifically for 'read' events in my case) - so I figured to just listen to all of the events and this works for me.