2011-07-27 32 views
1

我想在android上編寫我的第一個NFC應用程序。爲此,我使用Android開發者聯繫:http://developer.android.com/guide/topics/nfc/index.htmlAndroid NFC <tech-list> - 問題

這裏指定支持的技術,你必須創建一個XML文件是這樣的:

<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> 
     <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> 

我的問題是,在標籤我得到以下錯誤:「錯誤:發現標籤技術列表項目預計「

我的應用程序的目標是2.3.3。我認爲這必須在這個目標上工作...

任何想法?

謝謝!

+2

我已經解決了現在的問題。原因是我保存了xml文件的錯誤文件夾...不要直接在「values」文件夾中執行此操作! – SKAf8ce

+0

你應該回答你自己的問題。 – Kheldar

回答

6

片段從接收的活動我的應用程序的AndroidManifest.xml文件NFC意圖

<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> 

包含過濾器定義的文件是在res/XML/nfc_tech_filter.xml,看起來像這樣

<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> 

+0

謝謝,稍作修改,可以節省我的一天。我只需要閱讀一個帶有「NFC TAgInfo」應用程序的標籤,它就會給我提供數據來編寫正確的技術列表。 – Solostaran14

2

將每個<tech>項目放在單獨的<tech-list>節點中。

4

android SDK doc告訴: 在

<project-root>/res/xml/
文件夾中保存此文件(您可以將其命名爲任何內容)。

這樣,你可能保存在XML文件中的錯誤的文件夾。(你將它保存在<project-root>/res/values/

0

在我來說,我不得不創建內部res目錄xml。 這對我來說並不是很清楚。希望它能幫助別人。