2012-10-31 61 views
2

如何讀取扇區1的數據?authenticate是真的,我得到異常與IOException(「收發失敗」)。閱讀塊經典NFC

private String readSector() { 
    byte [] array={(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7}; 
    byte[] data = null; 
    final ByteArrayBuffer b = new ByteArrayBuffer(mMaxSize); 
    String sb=new String(); 
    boolean succes = false; 
    try { 
     mClassic.connect(); 
     succes = mClassic.authenticateSectorWithKeyA(1, array); 
     if (succes) { 
      b.append(mClassic.readBlock(3), 1, 16); 
      data = b.toByteArray(); 
     } 
     else 
      sb+="Authentication failed"; 
     mClassic.close(); 
    catch (final TagLostException tag) { 
     tag.printStackTrace(); 
     sb+="Tag Lost"; 
    } 
    catch (final IOException e) { 
     e.printStackTrace(); 
     sb+="IOEception"; 
    } 
} 
+0

此相同的問題的問題http://stackoverflow.com/questions/13154452/如何寫mifareclassic與自定義密鑰 –

+0

這個http://stackoverflow.com/questions/13154452/how-to-write-mifareclassic-with-custom-key不爲我回答 – amin

+0

您驗證部門1然後嘗試讀取扇區0中的塊3;完全像在另一個問題。 –

回答

2

找到它的扇區1塊4的數據至6,並且使用讀出的數據的代碼,

private String readMadSector() { 
     byte [] array={(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7}; 
     byte[] data = null; 
     byte [] b; 
     String sb=new String(); 
    boolean succes = false; 
    try { 
        mClassic.connect(); 
       succes = mClassic.authenticateSectorWithKeyA(1, array); 
            b=mClassic.readBlock(4); 

        sb+=convertHex(b); 


        b=mClassic.readBlock(5); 

        sb+=convertHex(b); 

        b=mClassic.readBlock(6); 

        sb+=convertHex(b); 
     else 
       sb+="Authentication failed"; 

     mClassic.close(); 

    } 

    catch (final TagLostException tag) { 
     tag.printStackTrace(); 
     sb+="Tag Lost"; 
    } 

    catch (final IOException e) { 
     e.printStackTrace(); 
     sb+="IOEception"; 
    } 





    return (sb.toString()); 
}