Android Studio NFC 读写卡程序 (一)

最近要做一个RFID 相关的项目,具体是关于 13.56MHz 的 NFC 卡的读写程序。

 1.NFC 常用场景 是 读卡,写卡 ,分享内容。 读写卡 主要 有两种  NDEF 读写模式 和 非 NDEF 读写模式

 2. 非NDEF  包含以下 常见数据格式:NfcA/NfcB/NfcF/NfcV/IsoDep/Ndef,意思是如果采用了不同的芯片(选用的标准不同,不同解决方案,) 卡的数据格式不同。

      就是 通过 techlist 设置 的选项,获取 通过  Tag.getTechlist()。

 3.     常见的 3种NFC相应程序(每种应用程序的启动页就是一个activity),分别对应三种过滤器,那么当一个tag靠近时,nexus s究竟选择哪种应用程序来处理呢?按照以下的          规 则,该规则成为intent发布系统规则:       

         activity 1中对intent过滤器设置了Android.nfc.action.NDEF_DISCOVERED的判断规则;

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

  activity 2中对intent过滤器设置了android.nfc.action.TECH_DISCOVERED的判断规则;

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

    activity 3中对intent过滤器设置了android.nfc.action.TAG_DISCOVERED的判断规则;

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

  按照优先级:最高的是 activity 1,第二是 activity2,第三是 activity3,当优先级 高的不满足条件时,才会进行第二个。

   NDEF,TECH,TAG,    TECH 需要 自己配置额外的xml 过滤。

原文地址:https://www.cnblogs.com/lfyy/p/7028843.html