Phonegap NFC在两个设备之间发送和读取数据



我正在尝试使用ionic angular应用程序中的phonegap NFC在两个支持NFC的设备之间发送信息(仅文本(。

到目前为止,我能够连接设备,Ndef事件侦听器捕获标记,但标记中的信息始终相同,它不会给我发送的消息。

我在识别NFC连接时发送标签的功能:

async connectPeerToPeer() {
var listener = NFC.addNdefListener(onSucess => {
console.log('Listening: ', onSucess);
}, onFail => {
console.log('Failure: ', onFail);
}).subscribe(event => {

NFC.share([Ndef.textRecord("hello world!")]).then(res => {
this.service.Popup("The write message was sent!", ["OK"]);
}).catch(err => {
this.service.Popup("Error: "+ err, ["OK"]);
});
});
}

我的事件接收标签:

NFC.addNdefListener((listening) => {
console.log("Listening");
}, (fail) => {
this.service.Popup(fail, ['OK']);
}).subscribe(ev => {
this.onNfc(ev);
});
onNfc(nfcEvent) {
console.log(nfcEvent);
}

这样,标签被传输到接收设备,但信息不是我正在发送的消息。

这是我在检查器上设置断点时得到的结果:

{"id":[0],"techTypes":["android.nfc.tech.Ndef"],"type":"android.ndef.unknown","maxSize":0,"isWritable":false,"ndefMessage":[{"tnf":1,"type":[85],"id":[],"payload":[3,112,108,97,121,46,103,111,111,103,108,101,46,99,111,109,47,115,116,111,114,101,47,97,112,112,115,47,100,101,116,97,105,108,115,63,105,100,61,105,111,46,105,111,110,105,99,46,115,116,97,114,116,101,114,38,102,101,97,116,117,114,101,61,98,101,97,109]},{"tnf":4,"type":[97,110,100,114,111,105,100,46,99,111,109,58,112,107,103],"id":[],"payload":[105,111,46,105,111,110,105,99,46,115,116,97,114,116,101,114]}],"canMakeReadOnly":false}

我假设我的消息可能在ndefMessage:

但是当我执行NFC.bytesToString(nfcEvent.tag.ndefMessage[0].payload)时,我得到以下字符串"play.google.com/store/apps/details?id=io.ionic.starter&feature=beam"

我是不是错过了什么?

提前感谢!

这可能是因为Android 10中不赞成使用Android Beam(对等NFC共享中使用的功能(。(操作系统正在寻找一个应用程序来替换这个缺失的功能(。

请参阅https://source.android.com/setup/start/android-10-release#nfc

展望未来,使用Wifi Direct或蓝牙在设备之间发送数据可能会更好,谷歌正在推动他们的";"附近";APIhttps://developers.google.com/nearby/作为替代品。

最新更新