Detecting problems with my app using NFC TAG

319 views Asked by At

I have developed an app which uses NFC function and got this TAG for my tests.

a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120054648901134.png

and its characteristics

a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120054925844663.png

All very well ..

and add the following lines in the config

<uses-feature android:name="android.hardware.nfc" android:required="false" />
             <intent-filter>
         <action android:name="android.nfc.action.TAG_DISCOVERED"/>
           <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
             <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>

Add my code so that when it detects the nfc and select my app

Get the UID .. And makes it right. (Then find out if you can get the different fields such as text.) Good. It works all right ..

my app blue http://nsae02.casimages.net/img/2014/11/19/mini_141119082121303903.png

my problem is then That same edit it using NFC TAG TAG Writer application

a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120055409818122.png

a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120055615627271.png

And I put a text and I go back to using my app but no longer appears in the list ..

Not my app http://nsae02.casimages.net/img/2014/11/19/mini_141119081714874308.png

Giving many turns and able to reappear in my app list formatting the NFC TAG

What am I doing wrong? If I have not put enough information please ask me. thank you very much

1

There are 1 answers

4
Michael Roland On BEST ANSWER

You need to setup proper intent filters that match the type of your tag. Currently you are using

  • an NDEF_DISCOVERED intent filter that won't trigger on most devices as it does not specify a data type, and
  • a TAG_DISCOVERED intent filter that is meant as a fall-back only when used inside the AndroidManifest.xml.

Consequently, what you experience is the fall-back behavior: While your tag does not contain an NDEF record, it will match the fall-back. As soon as you write a Text record to it, it will match all apps that registered for Text NDEF records and, therefore, won't trigger the fall-back anymore.

So, if you want to use a Text record on your tag, you could add the following intent filter for your activity:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>

Note that it is usually a bad idea to use Text records. First, they are meant for human-readable data only and, second, many apps register for them which makes it difficult for a user to select the right app in the activity chooser dialog.

This will still not catch the case where your tag does not contain any data (which is currently handled by the fall-back filter). In that case, you should use a TECH_DISCOVERED intent filter for the NfcV tag technology:

<intent-filter>
    <action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
           android:resource="@xml/filter_nfc" />

And in your res/xml folder you would need to create a file named filter_nfc.xml with this contents:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.NfcV</tech>
    </tech-list>
</resources>

Or when you want to register for multiple different tag technologies:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.NfcV</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcA</tech>
    </tech-list>
</resources>