我科尔多瓦应用程序不能启动之后NFC标签检测科尔、应用程序、多瓦、标签

2023-09-03 22:23:50 作者:骑驴追火箭

我使用阿帕奇科尔多瓦来构建Android应用程序。我与 NFC 功能的应用程序。

I am using Apache cordova to build android applications. I made an application with NFC feature.

我们已经写数据到NFC标签,用 MIMETYPE:对myApp / firstNFCApp 。在我的应用程序,只要检测到本 MIMETYPE 我的应用程序会读取数据并显示这些数据转换成用户友好的方式标记。这样一来我实现了,它的工作fine.This是code我写来从标签数据。

we already written data into NFC tag, with mimetype: myApp/firstNFCApp. Inside my application whenever detect tag with this mimetype my application will read data and showing that data into user friendly manner. This way I implemented, it's working fine.This was the code I written to fetch data from tag

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 。对于这一点,我下面code写的

Now I want to launch my application,whenever device detect a tag with mimetype: myApp/firstNFCApp . For this, I written following code

<intent-filter>
  <data android:mimeType="myApp/firstNFCApp" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

和我说安卓noHistory =真正的活动元素 androidManifest的.xml 文件。

我想:

如果该设备检测到任何标记与我的mimetype,要启动的应用程序也需要的触发该回调(手段,控制台会打印)。我现在用 chariotsolutions / PhoneGap的-NFC 插件。

If the device detect any tag with my mimetype,want to launch application also need's to trigger that callback(means,console will print).I am using chariotsolutions/phonegap-nfc plugin.

这是这样,我想它不工作。谁能帮助我谢谢你。

This is way, I tried it's not working. can anyone help me thank you.

推荐答案

为了共同接受的NFC意图在您的应用程序的整个NDEF消息,你需要定义一个适当的意图过滤器,在比赛的第一个记录上述NDEF消息:

In order to receive an NFC intent together with the whole NDEF message in your app, you would need to define a proper intent filter that matches the first record in the above NDEF message:

<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