Hallo Rashida,
you could try something like the following:
Code:
public void targetDetected(TargetProperties[] prop) {
[...]
String url = prop[0].getUrl();
conn = (NDEFTagConnection) Connector.open(url);
NDEFRecordType t = new NDEFRecordType(NDEFRecordType.EXTERNAL_RTD, "urn:nfc:ext:nfc-research.at:mydata");
NDEFMessage message = conn.readNDEF();
NDEFRecord[] records = message.getRecords();
if (records != null) {
for (int i = 0; i < records.length; ++i) {
if (records[i].getRecordType().equals(t)) {
[read data (i.e. tag name and tag status) from record]
}
}
}
byte[] payload = null;
[create payload from data (i.e. from tag name and tag status)]
NDEFRecord record = new NDEFRecord(t, null, payload);
message = new NDEFMessage(new NDEFRecord[] { record });
conn.writeNDEF(msg);
conn.close();
[...]
}
The code first reads an existing NDEF message from the tag and parses it for a certain record type (urn:nfc:ext:nfc-research.at:mydata). Then it creates a new message containing this record type with some payload and writes it back to the tag.
br,
Michael