×
Namespaces

Variants
Actions

Lendo UID de tags mifare embutidas

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

Compatibilidade
Plataforma(s):
Series 40

Artigo
Tradução:
Por valderind4
Última alteração feita por hamishwillee em 22 Oct 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 22 October 2013, at 05:19.
74 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.

×