开发者

NFC applications from market override "Complete action using" dialog entries

I have installed NXP TagWriter and NFC TagInfo on Nexus S, the same device used for my NFC application development. The problem is my application is not shown in the "Complete action using" dialog after Tag is read, only both installed from market are. After debugging it for a while, I have tried using demo application and the result was the same. What am I missing here? Do applications have to be installed from the market in order to have intent filters parsed properly?

Update

My intent-filter was simply

<intent-filter>
  <action   android:name="android.nfc.action.TAG_DISCOVERED" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

I have tried adding others as specified in manual, one by one as well as all together without success. Could it have something to do with mime type?

When NFC tag is read, only these two lines are related to the action and nothing else.

INFO/ActivityManager(111): Starting: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x10000000 cmp=com.nxp.nfc.tagwriter/.activities.DashboardActivity (has extras) } from pid 197
INFO/ActivityManager(111): Starting: Intent { cmp=com.nxp.nfc.tagwriter/.activities.ConfirmLicenseActivity } from pid 6250

Seeing android.nfc.action.TECH_DISCOVERED is triggered, I have added following intent-filter:

<intent-filter>
    <action   android:name="android.nfc.action.TECH_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

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

And res/xml/nfc_tech_filter.xml contains

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.IsoDep</tech>
        <tech>android.nfc.tech.NfcA</tech&开发者_运维知识库gt;
        <tech>android.nfc.tech.NfcB</tech>
        <tech>android.nfc.tech.NfcF</tech>
        <tech>android.nfc.tech.NfcV</tech>
        <tech>android.nfc.tech.Ndef</tech>
        <tech>android.nfc.tech.NdefFormatable</tech>
        <tech>android.nfc.tech.MifareClassic</tech>
        <tech>android.nfc.tech.MifareUltralight</tech>
    </tech-list>
</resources>


The reason TAG_DISCOVERED does not pop up your app is because it is the fall-back option: only when no matches for the NDEF_DISCOVERED and TECH_DISCOVERED intents can be found, TAG_DISCOVERED will be dispatched.

Since the NXP apps register for TECH_DISCOVERED, they will be preferred over your app. Your solution to include a TECH_DISCOVERED filter is correct, but the way you do it is wrong. The technologies in a "tech-list" block are AND-ed together; so in your example, this means that the filter will only match tags that have NfcA AND NfcB AND MifareClassic. Since NfcA and NfcB are very different technologies that don't go together, this filter will never match.

What you really want is an OR of all the different technologies. To do that, simply write multiple blocks containing only one technology:

<tech-list>
    <tech>android.nfc.tech.NfcA</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.NfcB</tech>
</tech-list>

This will match NfcA OR NfcB. Of course, you should make your filter as accurate as possible, to prevent the application list from clobbering up. If you're only interested in NfcA tags, don't claim the others.


Your tech list should consist of the combination of technologies you think your card supports. For example, if the card you want to read has NfcA, NfcB and MifareClassic then your techlist should have:

<tech-list>
    <tech>android.nfc.tech.NfcA</tech>
    <tech>android.nfc.tech.NfcB</tech>
    <tech>android.nfc.tech.MifareClassic</tech>
</tech-list>

You can have more than one tech-list tags in your resources. Only if a tag matches one of the tech-lists in your resources will your app be detected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜