Chunks of data can be transferred from one device to another with NFC, using the same messages used when writing to tags.
If we want to send messages from a device, we need to register a message with the NFC push system. We could create a custom message, as in the previous recipe, but here we will just send an HTTP URI to another device:
If we are targeting Android version 2.3 and above, we need to manually create the correct NDEF message payload:
byte httpType = 0x01; // 'http://www.' var theUri = Encoding.UTF8.GetBytes("xamarin.com"); var payload = new byte[theUri.Length + 1]; payload[0] = httpType; Array.Copy(theUri, 0, payload, 1, theUri.Length);
Once we have the payload, we create the message:
var record = new NdefRecord( NdefRecord.TnfWellKnown, NdefRecord.RtdUri.ToArray(), new byte[0], payload); var message = new NdefMessage(new[] { record });
If we are targeting Android version 4.0 and above, it is far easier to create the record:
var uri...