Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting application on NFC tag detection

I want to register an application to be launched when an NFC tag is detected. From searching around I found that I need to use

[IntentFilter(new[] { NfcAdapter.ActionTechDiscovered })]

on the main activity. However, the app doesn't launch (nor am I prompted to choose an application). Instead, a generic tag reader opens up.

Where is the problem?

like image 275
pikausp Avatar asked Dec 08 '25 06:12

pikausp


1 Answers

The ActionTechDiscovered intent filter requires a tech-list that specifies the tag technologies (or combinations of them) that your activity should be started for. You can specify the tech-list file using:

[IntentFilter (new[]{NfcAdapter.ActionTechDiscovered})]
[MetaData (NfcAdapter.ActionTechDiscovered, Resource="@xml/nfctech")]

You then need to place a file "nfctech.xml" into the folder "Resources/xml". Inside this file you can define all the tag technologies that you want to listen to. For instance, to listen for any tag technology, you would use:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.NfcA</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcB</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcF</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcV</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcBarcode</tech>
    </tech-list>
 </resources>
like image 125
Michael Roland Avatar answered Dec 10 '25 22:12

Michael Roland