Search code examples
javac#androidnfcpayload

get NFC payload in Android


I got two apps, one on android studio(java) an the other one in visual studio c# im trying to get the payload in both apps, im using the same nfc tag for this cases, but cant get the same bytes in the payload, and i need it to be like that for further operations.

this is my code in c#:

ProximityMessage message;
var rawMsg = message.Data.ToArray();
//rawMsg has a value of [209,1,19,84,2,105,116,30,170,127,251,46,128,69,76,132,236,80,34,204,234,212,192]

this is my code in android studio (java):

Parcelable[] rawMsgs= intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage[] msgs = null;
msgs = new NdefMessage[rawMsgs.length];
byte[] rawPayload = msgs[0].toByteArray();
//rawPayload has a value of [-47 , 1 , 19,  84 ,2 , 105 , 116,  30,  -86 , 127, -5 , 46, -128 , 69 , 76 , -124 , -20 , 80, 34, -52 , -22 , -44, -64]   

Solution

  • As Robert says it's just a display issue, for example the byte value of 209 (unsigned) is the same as -47 (signed), just the conversion to the displayed integer is handled differently.

    In Java if you print Byte.toUnsignedInt(rawPayload[0]) you will get 209