Esempio n. 1
1
		protected override void OnNewIntent(Intent intent)
		{
			if (_inWriteMode)
			{
				_inWriteMode = false;
				var tag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;

				if (tag == null)
				{
					return;
				}

				// These next few lines will create a payload (consisting of a string)
				// and a mimetype. NFC record are arrays of bytes. 
				var message = _inputText.Text += " " + DateTime.Now.ToString("HH:mm:ss dd/M/yyyy");
				_outputText.Text = message;
				var payload = Encoding.ASCII.GetBytes(message);
				var mimeBytes = Encoding.ASCII.GetBytes(ViewIsolationType);
				var isolationRecord = new NdefRecord(NdefRecord.TnfMimeMedia, mimeBytes, new byte[0], payload);
				var ndefMessage = new NdefMessage(new[] { isolationRecord });

				TryAndFormatTagWithMessage(tag, ndefMessage);  
				if (!TryAndWriteToTag(tag, ndefMessage))
				{
					// Maybe the write couldn't happen because the tag wasn't formatted?
					TryAndFormatTagWithMessage(tag, ndefMessage);                    
				}
			}
		}
 public NdefRecord CreateMimeRecord(String mimeType, byte [] payload)
 {
     byte [] mimeBytes = Encoding.UTF8.GetBytes (mimeType);
     NdefRecord mimeRecord = new NdefRecord (
         NdefRecord.TnfMimeMedia, mimeBytes, new byte [0], payload);
     return mimeRecord;
 }
        /// <summary>
        /// This method is called when an NFC tag is discovered by the application.
        /// </summary>
        /// <param name="intent"></param>
        protected override void OnNewIntent(Intent intent)
        {
            if (_inWriteMode)
            {
                _inWriteMode = false;
                var tag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;

                if (tag == null)
                {
                    return;
                }

                // These next few lines will create a payload (consisting of a string)
                // and a mimetype. NFC record are arrays of bytes.
                var payload = Encoding.ASCII.GetBytes(GetRandomHominid());
                var mimeBytes = Encoding.ASCII.GetBytes(ViewApeMimeType);
                var apeRecord = new NdefRecord(NdefRecord.TnfMimeMedia, mimeBytes, new byte[0], payload);
                var ndefMessage = new NdefMessage(new[] { apeRecord });

                if (!TryAndWriteToTag(tag, ndefMessage))
                {
                    // Maybe the write couldn't happen because the tag wasn't formatted?
                    TryAndFormatTagWithMessage(tag, ndefMessage);
                }
            }
        }