我在用Apache cordova
构建 Android 应用程序。我提出了申请NFC
特征。
我们已经将数据写入 NFC 标签,其中mimetype: myApp/firstNFCApp
。在我的应用程序中,每当检测到带有此标记的标签时mimetype
我的应用程序将读取数据并以用户友好的方式显示该数据。我以这种方式实现,工作正常。这是我编写的从标签获取数据的代码
nfc.addNdefListener(
function(nfcEvent){
console.log(nfc.bytesToString(nfcEvent.tag.ndefMessage[0].payload));
},
function(){
console.log("sucessfully created");
},
function(){
console.log("something went wrong");
}
);
现在我想启动我的应用程序,每当设备检测到标签时mimetype: myApp/firstNFCApp
。为此,我编写了以下代码
<intent-filter>
<data android:mimeType="myApp/firstNFCApp" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
我添加了android:noHistory="true"
to activity
元素在androidManifest.xml
file.
我想要的是 :
如果设备检测到任何具有我的 mimetype 的标签,想要启动应用程序还需要触发该回调(意味着,控制台将打印)。我正在使用chariotsolutions/phonegap-nfc
plugin.
这个办法,我试过了,不行。谁能帮我谢谢。
为了在您的应用程序中接收 NFC 意图以及整个 NDEF 消息,您需要定义一个与上述 NDEF 消息中的第一条记录匹配的正确意图过滤器:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
请参阅如何处理 NFC
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)