2012-09-24 86 views
0

我正在嘗試使Android應用程序寫NFC標籤。要看到如何做到這一點,我已經下載了一個例子。但是,該示例不起作用。它說它無法驗證。這隻能表示它對這種類型的卡使用了不正確的密鑰。奇怪的是,即使是KEY_DEFAULTKEY_MIFARE_APPLICATION_DIRECTORY鍵也無法在我的空白卡上工作。 Mifare是否以任何方式更換了鑰匙?Mifare Classic 1k寫鑰匙

編輯:這是我的代碼。

  /* Authenticate the MAD Sector, sector 1, with key A */ 
     succes = mClassic.authenticateSectorWithKeyA(
       1, key); 
     if (succes) { 
      /* Authentication succeeded */ 

      /* 
      * This will read a 16-byte block in this sector 
      * It is an I/O operation and will block until complete. 
      * It must not be called from the main application thread. 
      **/ 
      b.append(mClassic.readBlock(1), 0, 16); 
      b.append(mClassic.readBlock(2), 0, 16); 
      b.append(mClassic.readBlock(3), 0, 16); 
      data = b.toByteArray(); 
     } 
     /* Authentication failed */ 
     else 
      sb.append("Authentication failed"); 
     mClassic.close(); 

    } 

我用下面的按鍵已經嘗試過了:

MifareClassic.KEY_DEFAULT 
MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY 
00 00 00 00 00 00 
ff ff ff ff ff ff 

都無濟於事..

+0

參閱本博客:http://nearfieldcommunication.com/developers/android/ http://mifareclassicdetectiononandroid.blogspot.jp/2011/04/reading-mifare-classic- 1k-from-android.html希望這將有助於您瞭解Google理解 –

回答

2

我對Ubiqconn平板電腦並不熟悉。我要做的第一件事就是檢查設備中的NFC實現是否確實支持MIFARE。在您的主要活動的onCreate()地址:

public void onCreate(Bundle bundle) { 
    ... 
    if (!getPackageManager().hasSystemFeature("com.nxp.mifare")) { 
    Toast.makeText(this, "No MIFARE support!", Toast.LENGTH_LONG).show(); 
    } 
} 
+0

猜猜......沒有MIFARE支持!'謝謝你的幫助,現在我要告訴我的老闆他訂購了200個錯誤的標籤。 –

+0

有趣。我搜索了該設備,製造商的網站似乎聲稱他們支持MIFARE。所以我想知道發生了什麼。 –

+0

您提到設備運行2.3.4。 2.3的[Android Compatibility Device Description](http://static.googleusercontent.com/external_content/untrusted_dlcp/source.android.com/en//compatibility/android-2.3-cdd.pdf)沒有提及「com.nxp .mifare「,而[CDD for 4.1](http://static.googleusercontent.com/external_content/untrusted_dlcp/source.android.com/en//compatibility/4.1/android-4.1-cdd.pdf)。有些可能還有希望。 –

1

要麼你有你的應用程序(S)的bug,或者有鑰匙已定製。使用類似NFC TagInfo的應用程序來檢查您是否可以使用默認鍵讀取/寫入卡片。如果它不起作用,請聯繫向你出售卡片的人,並詢問他們鑰匙是什麼。

+0

我無法從Play商店安裝應用,因爲我的測試設備已經紮根,並且沒有與其關聯的Play商店/ Google帳戶。 –

+0

在這種情況下,請嘗試使用桌面閱讀器或安裝了Google Play的其他Android設備閱讀您的卡片。順便說一句,根植並不妨礙您使用Play商店。你使用什麼設備? –

+0

我正在使用運行Android 2.3.4的Ubiqconn平板電腦。確實可以安裝Google Play,但無法將Google帳戶添加到設備。設置 - >帳戶和同步 - >添加帳戶僅允許Microsoft Exchange帳戶出於某種原因。 我沒有桌面NFC讀卡器。 –

相關問題