How write tag NFC with MifareClassic in bytes array

Viewed 28

I'm trying to write to a tag but I don't want to send a text, I want to send an array of bytes because that way I'll have a better sending control and I'll be able to establish fixed data according to the position of the array when I read it, I was investigating and I didn't find anything in particular .

The tag I have has NfcV and Ndef as techlist. I tried MifareClassic but it doesn't show up as null. Any other ideas please.

I want to emphasize that the byte array must be exclusively the data that I send, because I have seen other scripts like NdefRecord but they respect parameters at the beginning of the frame by writing data that I do not want but that function needs it to write.

private void write(String text, Tag tag) throws IOException, FormatException {
    //byte[] data= Const.ResponseDataDeviceWrite;
    //NdefRecord records = new NdefRecord(data);
   // NdefRecord[] records = { createRecord(text) };
    byte[] data = {66,104,111,108,97,32,32,32,32,32,32,32,32};
    //records=data;
   // NdefMessage  message = new NdefMessage(records);
    //NdefMessage message = createRecord(text);
    // Get an instance of Ndef for the tag.
    Ndef ndef = Ndef.get(tag);
  
    // If Ndef.get is null then try formatting it and adding message
    if (ndef != null) {
        // Enable I/O
        ndef.connect();
        // Write the message
       /* NdefRecord[] records = {
                NdefRecord.createMime("text/plain",  data)
        };*/
        //NdefMessage  message = new NdefMessage(data);
        ndef.writeNdefMessage(new NdefMessage(new NdefRecord(NdefRecord.TNF_UNKNOWN, null, null, data)));
        //ndef.writeNdefMessage(message);
        // Close the connection
        ndef.close();
    } else {
        NdefFormatable ndefFormatable = NdefFormatable.get(tag);
        // Really should do a null test on ndefFormatable here but as the code is looking for an exception don't test for null
        ndefFormatable.connect();
        // Format at write message at the same time
       // ndefFormatable.format(message);
        ndefFormatable.close();
    }

}

Example what came out in writing and what should be, previously it was possible to write but in an application in c#

enter image description here

0 Answers
Related