title: Read NFC Mifare Ultralight cards with javax.smartcardio
body: <p>I try to read NFC Mifare Ultralight cards (page 4) with an ACR1252U and the javax.smartcardio Java library this way:</p>
  
  <pre><code>TerminalFactory factory = TerminalFactory.getDefault();
  List&lt;CardTerminal&gt; terminals = factory.terminals().list();
  System.out.println("Terminals: " + terminals);
  
  CardTerminal terminal = terminals.get(0);
  
  System.out.println("Waiting for a card..");
  
  if (terminal == null)
      return;
  terminal.waitForCardPresent(0);
  
  Card card = terminal.connect("T=1");
  System.out.println("Card: " + card);
  System.out.println("ATR: " + bytesToHex(card.getATR().getBytes()));
  System.out.println("Protocol: " + card.getProtocol());
  
  CardChannel channel = card.getBasicChannel();
  
  CommandAPDU command = new CommandAPDU(new byte[]{(byte) 0xFF, 
      (byte) 0xB0, (byte) 0x00, (byte) 0x04, (byte) 0x04});
  ResponseAPDU response = channel.transmit(command);
  
  if (response.getSW1() == 0x90) {
      // success command
      byte[] data = response.getData();
      System.out.println(new String(data));
  }
  </code></pre>
  
  <p>Sometimes it works and sometimes not (with the same card)</p>
  
  <p>When the reading works, I get these values:</p>
  
  <ul>
  <li>ATR = 0x3B8F8001804F0CA0000003060300030000000068</li>
  <li>SW1 = 0x90</li>
  <li>SW2 = 0x00</li>
  </ul>
  
  <p>And when it doesn't work, I get these:</p>
  
  <ul>
  <li>ATR = 0x3B80800101</li>
  <li>SW1 = 0x63</li>
  <li>SW2 = 0x00</li>
  </ul>
  
  <p>Any idea what I'm doing wrong?</p>