Categories: Code Examples | Java | NFC
This page was last modified 09:00, 3 January 2008.
Reading UID from embedded Mifare tag
From Forum Nokia Wiki
import java.io.IOException; import javax.microedition.io.Connector; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; import com.nokia.nfc.nxp.mfstd.MFStandardConnection; public class GetMyUID extends MIDlet { Form form = new Form("GetMyUID"); public GetMyUID() { } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { Display.getDisplay(this).setCurrent(form); MFStandardConnection myTag = null; try { myTag = (MFStandardConnection) Connector.open(System.getProperty("internal.mf.url")); form.append("My UID: " + decodeUID(myTag.getManufacturerBlock().getUID())); } catch (Exception e) { form.append(e.toString()); } finally { if (myTag != null) { try { myTag.close(); } catch (IOException e) { form.append(e.toString()); } } } } private String decodeUID(byte[] uid) { byte[] result = new byte[uid.length*2]; for (int i = 0; i < uid.length; i++) { result[i*2] = (hexChars[(uid[i] & 0xF0) >>> 4]); result[i*2+1] = (hexChars[uid[i] & 0x0F]); } return new String(result); } private final static byte[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; }
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| JavaCard & Mifare Access (6131) | geri-m | Near Field Communication | 10 | 2007-04-20 19:13 |
| Auto Launching MIDlet | emirant1 | Mobile Java General | 2 | 2007-01-31 10:07 |
| NDEF and Mifare | cgauld | Near Field Communication | 1 | 2007-07-09 13:14 |
| N6131 Secure Ele Version | lovercjs | Near Field Communication | 3 | 2007-09-27 04:54 |
| NDEF Tag Image File formating | ustagnu | Near Field Communication | 3 | 2007-09-03 12:37 |
