Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Reading UID from embedded Mifare tag

From Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s):
Series 40
Article
Created: tsavinen (03 Jan 2008)
Last edited: hamishwillee (23 Jul 2013)
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' };
}
This page was last modified on 23 July 2013, at 08:25.
75 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×