Android NFC <tech-list> - problem

与世无争的帅哥 提交于 2019-12-08 19:48:28

Snippet from my app's AndroidManifest.xml file for the activity that receives NFC intents

<activity
        android:name=".activity.ClientActivity"
        android:screenOrientation="portrait"
        android:label="@string/app_name"
        android:description="@string/app_name"
        android:icon="@drawable/ttlogo">
        <intent-filter>
            <action
                android:name="android.nfc.action.TECH_DISCOVERED"/>
        </intent-filter>
        <meta-data
            android:resource="@xml/nfc_tech_filter"
            android:name="android.nfc.action.TECH_DISCOVERED" />
        <intent-filter>
            <action
                android:name="android.nfc.action.TAG_DISCOVERED" />
            <category
                android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW" />
            <category
                android:name="android.intent.category.DEFAULT" />
            <data
                android:scheme="http"
                android:host="www.ttag.be" />
        </intent-filter>
    </activity>

The file containing the filter definition is in res/xml/nfc_tech_filter.xml and looks like this

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!--  Touchatag tag -->
<tech-list>
    <tech>android.nfc.tech.NfcA</tech>        
    <tech>android.nfc.tech.Ndef</tech>
    <tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
<!--  DESFire tag -->
<tech-list>
    <tech>android.nfc.tech.NfcA</tech>        
    <tech>android.nfc.tech.IsoDep</tech>
    <tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
<!--  Any Tag -->
<tech-list>
    <tech>android.nfc.tech.NfcA</tech>        
</tech-list>

The android SDK doc tell: Save this file (you can name it anything you wish) in the

 <project-root>/res/xml/ 
folder.

so,you probably save your xml file in an wrong folder.(did you save it in <project-root>/res/values/ )

Put each of the <tech> item in a separate <tech-list> node.

In my case I had to create the directory xml inside res. It was not very clear for me. Hope it helps someone.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!