NFC在react-native和android中使用foregroundDispatch

问题描述 投票:1回答:1

我正在尝试在react-native中开发一个应用程序,应该使用android的foreground dispatch system来阻止任何其他活动之前的nfc事件。 android部分不是问题,我在原生应用程序中完成了它。

在使用react-native的应用程序中,这样做的正确方法是什么?

react-native nfc
1个回答
2
投票

我最终添加了挂起意图的创建,并添加了标签/ NDEF过滤器到MainActivity。然后onNewIntent解析相关数据并将其转发给js via

getReactInstanceManager()
  .getCurrentReactContext()
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
  .emit("nfcTagEvent", params);

然后,在我的主要RN组件中

DeviceEventEmitter.addListener('nfcTagEvent', event =>
  // do something with event
);
© www.soinside.com 2019 - 2024. All rights reserved.