我正在尝试在react-native中开发一个应用程序,应该使用android的foreground dispatch system来阻止任何其他活动之前的nfc事件。 android部分不是问题,我在原生应用程序中完成了它。
在使用react-native的应用程序中,这样做的正确方法是什么?
我最终添加了挂起意图的创建,并添加了标签/ NDEF过滤器到MainActivity
。然后onNewIntent
解析相关数据并将其转发给js via
getReactInstanceManager()
.getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("nfcTagEvent", params);
然后,在我的主要RN组件中
DeviceEventEmitter.addListener('nfcTagEvent', event =>
// do something with event
);