2015-09-28 225 views
0

我正在研究一個需要讀取RFID標籤的應用程序。請告訴我,Android設備支持哪些RFID標籤,是否需要額外的硬件或其他東西來讀取RFID標籤,或者只能通過NFC進行。我做就可以[R & d我知道的話,可以通過讀取NFC RFID標籤和使用我開發者網站integerated的代碼,但我不能能夠讀取(用於考勤RFID標籤)的RFID標籤使用NFC讀取RFID標籤

public class NFCForegroundUtil { 
    private NfcAdapter nfc; 

    private Activity activity; 
    private IntentFilter intentFiltersArray[]; 
    private PendingIntent intent; 
    private String techListsArray[][]; 

    public NFCForegroundUtil(Activity activity) { 
     super(); 
     this.activity = activity; 
     nfc = NfcAdapter.getDefaultAdapter(activity.getApplicationContext()); 

     intent = PendingIntent.getActivity(activity, 0, new Intent(activity, 
       activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 

     IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); 

     try { 
      ndef.addDataType("*/*"); 
     } catch (IntentFilter.MalformedMimeTypeException e) { 
      throw new RuntimeException("Unable to speciy */* Mime Type", e); 
     } 
     intentFiltersArray = new IntentFilter[] { ndef }; 

     techListsArray = new String[][] { new String[] {IsoDep.class.getName(),NfcV.class.getName(), NfcA.class.getName(), NfcB.class.getName(), NfcF.class.getName(), Ndef.class.getName(), NdefFormatable.class.getName(), MifareClassic.class.getName(), MifareUltralight.class.getName()} }; 

    } 

    public void enableForeground() 
    { 
     Log.d("demo", "Foreground NFC dispatch enabled"); 
     nfc.enableForegroundDispatch(
       activity, intent, intentFiltersArray, techListsArray); 
    } 

    public void disableForeground() 
    { 
     Log.d("demo", "Foreground NFC dispatch disabled"); 
     nfc.disableForegroundDispatch(activity); 
    } 

    public NfcAdapter getNfc() { 
     return nfc; 
    } 
} 

回答

0

你可以閱讀這個線程Reading RFID with Android phones

NFC guy評論:

你可以考慮NFC標籤RFID標籤的特殊情況。更具體地說,Android支持ISO 14443和ISO 15693兼容的RFID標籤。

的folloing代碼用於讀取NFCv(ISO 15693) 在清單:

<uses-permission android:name="android.permission.NFC" /> 

    <activity 
     android:name=".SplashActivity"> 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </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_list"> 
     </meta-data> 
    </activity> 

nfc_tech_list.xml會是這樣的:

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

然後你只需要調整你的活動,如果你的應用程序關閉,onCreate被調用,如果應用程序打開,然後t每次檢測到nfc時,都會調用onNewIntent。先註冊NFC:

@Override 
public void onResume() { 
    super.onResume(); 
    if(checkNFCAvailability()) 
     mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    mNfcAdapter.disableForegroundDispatch(this); 

} 

private boolean checkNFCAvailability() { 
    PackageManager pm = getPackageManager(); 

    //NFC NOT AVAILABLE 
    if(!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) { 
     return false; 
    } else { 
     mNfcAdapter = NfcAdapter.getDefaultAdapter(this); 
     mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 

     //NFC AVAILABLE BUT DISABLED 
     if(Build.VERSION.SDK_INT >= 16) { 
      startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)); 
     } else { 
      startActivity(new Intent(Settings.ACTION_SETTINGS)); 
     } 

     //NFC AVAILABLE AND ENABLED 
     else {     
      mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 
      IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); 
      mFilters = new IntentFilter[] {ndef,}; 
      mTechLists = new String[][] { new String[] { android.nfc.tech.NfcV.class.getName() } };  
     } 
    } 
} 


@Override 
public void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { 

     myTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); 

     //Do your logic using operations like 
     NfcV nfcvTag = NfcV.get(myTag); 
     nfcvTag.connect(); 
     response = nfcvTag.transceive(new byte[]); //your address 
     nfcvTag.close(); 

    } 
} 

您必須導入

import android.nfc.Tag; 
import android.nfc.tech.NfcV; 
import android.content.pm.PackageManager; 
import android.nfc.NfcAdapter;