/* * Potentially useful links * https://stackoverflow.com/questions/36270238/android-nfc-ndef-writendefmessage-throws-ioexception-and-erases-tag-data * https://stackoverflow.com/questions/40288795/android-nfca-connect-nfca-transceive-nfca-settimeout-and-nfca-getmaxtran * https://stackoverflow.com/questions/29718618/get-the-data-payload-of-a-tag * https://stackoverflow.com/questions/42819027/nfca-transceive-commands-documentation-nfc-a-iso-14443-3a* */ public void Callback(object obj) { if (obj is Intent intent) { Logging.Log(LogType.Information, $"Callback object is of type 'Intent'"); Tag rawTag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag; NfcA tag = NfcA.Get(rawTag); tag.Connect(); byte[] result = tag.Transceive(CommandFactory.Instance().GetByteCommand(NfcByteCommand.Select)); if (!(result[0] == (byte)0x90 && result[1] == (byte)0x00)) { throw new IOException("could not select applet"); } result = tag.Transceive(CommandFactory.Instance().GetByteCommand(NfcByteCommand.GetString)); int len = result.Length; if (!(result[len - 2] == (byte)0x90 && result[len - 1] == (byte)0x00)) { throw new RuntimeException("could not retrieve msisdn"); } byte[] data = new byte[len - 2]; Array.Copy(result, data, len - 2); var str = Encoding.Default.GetString(data).Trim(); tag.Close(); } }
public byte[] NfcA_WritePage(NfcA nfca, byte Page) { return(nfca.Transceive(new byte[2] { NfcA_Write_Key, Page })); }