NFC 在 react-native 和 android 中使用 foregroundDispatch
NFC using foregroundDispatch in react-native and android
我正在尝试在本机反应中开发一个应用程序,它应该使用 android 的 foreground dispatch system 在任何其他 activity 之前拦截 nfc 事件。
android 部分没有问题,我在原生应用中已经完成了。
在使用 react-native 的应用中正确的做法是什么?
我最终添加了待处理意图的创建,并向 MainActivity
添加了 tag/NDEF 个过滤器。然后onNewIntent
解析相关数据,通过
中转给js
getReactInstanceManager()
.getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("nfcTagEvent", params);
然后,在我的主要 RN 组件中
DeviceEventEmitter.addListener('nfcTagEvent', event =>
// do something with event
);
我正在尝试在本机反应中开发一个应用程序,它应该使用 android 的 foreground dispatch system 在任何其他 activity 之前拦截 nfc 事件。 android 部分没有问题,我在原生应用中已经完成了。
在使用 react-native 的应用中正确的做法是什么?
我最终添加了待处理意图的创建,并向 MainActivity
添加了 tag/NDEF 个过滤器。然后onNewIntent
解析相关数据,通过
getReactInstanceManager()
.getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("nfcTagEvent", params);
然后,在我的主要 RN 组件中
DeviceEventEmitter.addListener('nfcTagEvent', event =>
// do something with event
);