【发布时间】:2021-02-12 08:52:41
【问题描述】:
我正在尝试使用 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"
我错过了什么吗?
提前致谢!
【问题讨论】:
-
您为每台设备尝试的操作系统版本是什么?
-
安德鲁,我用的是 Galaxy S9 Plus 和华为 P30
-
操作系统:Android 版本 10