Hallo,

Originally Posted by
DixieFlatline
I created Mifare1k tag with nfc manager. i wrote some plain text on it. How should i read it?
That depends on what type of tag-content you created:
* If you created an NDEF tag (based on MIFARE 1K) with an NDEF record that has the MIME media type text/plain or
* if you created an NDEF tag (based on MIFARE 1K) with an NDEF Text record:
You can either use an NDEFRecordListener to listen for the expected type of record or you can use a TargetListener to listen for any NDEF tag and then parse its NDEF message for the expected record.
* If you created a MIFARE 1K tag and then directly edited its contents in the hex editor window without using the NDEF format:
In this case you need to access the MIFARE tag through Nokia's MIFARE API (see package com.nokia.nfc.nxp.mfstd).

Originally Posted by
DixieFlatline
I tried the code below(modified one other example), bui it crashes my emulator as i run it (nokia 6212 classic). Do you have any piece of code that works?
Your code looks OK, except that you don't need large portions of it. One thing I found is the line
Code:
form.addCommand(writeCommand);
In this line you use the uninitialized variable writeCommand. In my opinion this should lead to a NULL pointer exception, but it should not crash the emulator.
From your code I would guess that you have created an NDEF tag with an NDEF record of the MIME media type text/plain. So the easiest way to access (read-only) your NDEF record would be an NDEFRecordListener like this:
Code:
public void startApp() {
dm = DiscoveryManager.getInstance();
try {
dm.addNDEFRecordListener(this, new NDEFRecordType(NDEFRecordType.MIME, "text/plain"));
} catch (Exception e) { }
form = new Form("Reading Mode");
exitCommand = new Command("Exit", Command.EXIT, 1);
form.addCommand(exitCommand);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
}
public void recordDetected(NDEFMessage msg) {
if (msg != null) {
for (int i = 0; i < msg.getNumberOfRecords(); ++i) {
NDEFRecord rec = msg.getRecord(i);
String recT = rec.getRecordType().getName();
String recP = "";
if (rec.getPayloadLength() > 0) {
byte[] payload = rec.getPayload();
try {
for (int ll = 0; ll < payload.length; ++ll) {
if (((payload[ll] >= 0) && (payload[ll] <= 8)) ||
((payload[ll] >= 14) && (payload[ll] <= 31))) {
payload[ll] = 46;
}
}
recP = new String(payload, "ISO8859-1");
} catch (Exception e) { }
}
form.append("Record " + i + ":\n"
+ (recT != null ? "TYPE=" + recT + "\n" : "")
+ "--- BEGIN DATA ---\n" + recP + "\n--- END DATA ---\n\n");
}
}
}
Of course, you should also remove any unused NDEFRecordListener as soon as you no longer need it.
br,
Michael