Example #1
0
 public void RaiseNewTag(NfcTag tag)
 {
     if (NewTag != null)
     {
         NewTag(this, tag);
     }
 }
        private void card_format_proc(NfcTag _tag)
        {
            try
            {
                var again = true;

FormatAgain:
                if (_tag.Format())
                {
                    var msg = "Formatted Tag with UID " + _tagUID + " Successfully.";
                    SuccessNotify("Success|" + msg);
                    this.BeginInvoke(new OnTagFormatInvoker(OnTagFormat), _tag);
                }
                else
                {
                    if (again)
                    {
                        again = false;
                        goto FormatAgain;
                    }

                    var msg = "Tag Format Failure. Please try again or contact Support.";
                    WarnNotify("Warning|" + msg);
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
Example #3
0
        void HandleNewTag(object sender, NfcTag e)
        {
            var                       contentRead        = Encoding.ASCII.GetString(e.NdefMessage[0].Payload);
            string                    serialNumber       = BitConverter.ToString(e.Id);
            var                       r                  = new CrudApi(App.btoken);
            Uri                       restUri            = new Uri(Constants.RestURLAddAttendance);
            string                    NFCContentUploaded = Guid.NewGuid().ToString();
            AddAttendanceBody         body               = new AddAttendanceBody(serialNumber, contentRead, NFCContentUploaded);
            AddAttendanceResponseBody responseBody       = null;

            try
            {
                var spRecord = new NdefTextRecord
                {
                    Payload = Encoding.ASCII.GetBytes(NFCContentUploaded)
                };
                var msg = new NdefMessage {
                    spRecord
                };
                device.WriteTag(msg);
                responseBody = Task.Run(async() =>
                                        { return(await r.PostAsync <AddAttendanceBody, AddAttendanceResponseBody>(restUri, body)); }).Result;
                string text = responseBody.EmployeeInfo + " succesfully added attendance no." + responseBody.ID + " on point " + System.Environment.NewLine + responseBody.TagInfo;
                ShowSuccess(text);
            }
            catch (Exception excp)
            {
                ShowFail("An error occurred.");
                DependencyService.Get <IAudio>().PlayMp3File("door.mp3");
                return;
            }
            Device.StartTimer(System.TimeSpan.FromSeconds(5), () => { ShowBasic(); return(true); });
            return;
        }
Example #4
0
        public NfcForms()
        {
            NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService);

            nfcDevice = NfcManager.DefaultAdapter;
            nfcTag    = new NfcTag();
        }
Example #5
0
        /// <summary>
        /// ポーリング
        /// </summary>
        /// <returns>カード情報,NULL=未検出</returns>
        public NfcTag Polling(ushort sysCode)
        {
            NfcTag tag = reader.Polling();

            if ((useCard & UseCard.Felica) == 0 && tag is Felica)
            {
                tag.Release();
                tag = null;
            }
            else if ((useCard & UseCard.Mifare) == 0 && tag is Mifare)
            {
                tag.Release();
                tag = null;
            }

            if (tag is Felica)
            {
                try
                {
                    tag = ((IFelicaReader)reader).Select(sysCode);
                }
                catch (PcscException)
                {
                    tag.Release();
                    tag = null;
                }
            }
            return(tag);
        }
Example #6
0
 public NfcScannerService()
 {
     using (NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService))
     {
         _nfcDevice = NfcManager.DefaultAdapter;
     }
     _nfcTag = new NfcTag();
 }
        void OnTagRead(NfcTag tag)
        {
            try
            {
                string msg;
                _tag = tag;

                if (_tag == null)
                {
                    msg = "Internal error, The Tag is Invalid!";
                    WarnNotify("Warning|" + msg);
                    return;
                }

                if ((tag.Content == null) || (tag.Content.Count == 0))
                {
                    if (!tag.IsLocked())
                    {
                        msg = "The Device has no valid content yet. You may proceed with Tag Writting.";
                        WarnNotify("Warning|" + msg);
                    }
                    else
                    {
                        msg = "The Tag has no valid content, but is not writable";
                        WarnNotify("Warning|" + msg);
                    }
                }
                else
                {
                    var ndef = tag.Content.FirstOrDefault();
                    switch (ndef)
                    {
                    case null:
                        msg = "This Tag is Empty.";
                        WarnNotify("Warning|" + msg);
                        return;

                    case RtdSmartPoster smart:
                        txtStudentMatric.Text = smart.Title.FirstOrDefault()?.Value ?? "";

                        btnStudentRequest_Click(this, EventArgs.Empty);

                        msg = "Valid EdBoxPremium Student.";
                        SuccessNotify("Awesome|" + msg);
                        break;

                    default:
                        msg = "Data found but its not a EdBoxPremium Data.";
                        WarnNotify("Warning|" + msg);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
Example #8
0
        public void RaiseTagTagDisconnected(NfcTag tag)
        {
            _nfcTag.IsConnected = false;

            if (TagDisconnected != null)
            {
                TagDisconnected(this, tag);
            }
        }
Example #9
0
        public void RaiseTagConnected(NfcTag tag)
        {
            _nfcTag.IsConnected = true;

            if (TagConnected != null)
            {
                TagConnected(this, tag);
            }
        }
        private void card_read_proc()
        {
            NfcTag tag = null;
            string msg = null;

            try
            {
                if (NfcTagType2.RecognizeAtr(_cardchannel))
                {
                    if (NfcTagType2.Recognize(_cardchannel))
                    {
                        tag = NfcTagType2.Create(_cardchannel);
                        if (tag == null)
                        {
                            WarnNotify("Warning|An error has occured while reading the Tag's content");
                        }
                    }
                    else
                    {
                        msg = "From the ATR it may be a NFC type 2 Tag, but the content is invalid";
                        WarnNotify("Warning|" + msg);
                    }
                }
                else
                {
                    if (NfcTagType4.Recognize(_cardchannel))
                    {
                        tag = NfcTagType4.Create(_cardchannel);
                        if (tag == null)
                        {
                            msg = "An error has occured while reading the Tag's content";
                            WarnNotify("Warning|" + msg);
                        }
                    }
                    else
                    {
                        msg = "Unrecognized or unsupported card";
                        WarnNotify("Warning|" + msg);
                    }
                }

                if (tag != null)
                {
                    this.BeginInvoke(new OnTagReadInvoker(OnTagRead), tag);
                }
                else
                {
                    this.BeginInvoke(new OnErrorInvoker(OnError), msg, "This is not a valid NFC Tag");
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
Example #11
0
        /// <summary>
        /// ポーリング(Mifare)
        /// </summary>
        /// <returns>カード情報,NULL=未検出</returns>
        public Mifare Polling()
        {
            NfcTag tag = reader.Polling();

            if (tag != null && !(tag is Mifare))
            {
                tag.Release();
                tag = null;
            }
            return((Mifare)tag);
        }
 void OnTagFormat(NfcTag _tag)
 {
     try
     {
         MessageBox.Show(@"Tag Format Successful.");
         card_read_proc();
     }
     catch (Exception ex)
     {
         ErrorHandler.TreatError(ex);
     }
 }
Example #13
0
        private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
        {
            var bytes = message.Data.ToArray();
            List <NdefRecord> records = Ndef.parse(bytes);

            NfcTag tag = new NfcTag(records);

            // calling a global js method to fire an nfc event
            ScriptCallback script = new ScriptCallback("fireNfcTagEvent", new string[] { "ndef", JsonHelper.Serialize(tag) });

            this.InvokeCustomScript(script, false);
        }
Example #14
0
 private void btRelease_Click(object sender, EventArgs e)
 {
     try
     {
         card.Release();
         card        = null;
         tbCard.Text = "";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 /// <summary>
 /// Retrieves NFC Tag information.
 /// </summary>
 /// <param name="type">The Tag type</param>
 /// <param name="support">Whether NDEF messages are supported or not</param>
 /// <param name="size">Stored NDEF message size in Tag</param>
 /// <param name="maxSize">Maximum NDEF message size that can be stored in Tag</param>
 /// <returns>Returns true if tag type was successfully obtained, false otherwise</returns>
 public bool GetTagInfo(ref string type, ref bool support, ref uint size, ref uint maxSize)
 {
     try
     {
         NfcTag nfcTag = tagAdapter.GetConnectedTag();
         type    = nfcTag.Type.ToString();
         support = nfcTag.IsSupportNdef;
         size    = nfcTag.NdefSize;
         maxSize = nfcTag.MaximumNdefSize;
         return(true);
     }
     catch (Exception e)
     {
         Tizen.Log.Debug("NFC_APP", "Failed get Tag Type " + e.Message);
         return(false);
     }
 }
Example #16
0
        /*
         * card_write_proc
         * ---------------
         * This is the core function to try read a card, and maybe recognize it as an NFC tag
         * The function is executed in a background thread, so the application's window keeps
         * responding during the dialog
         */
        private void card_write_proc(object _tag)
        {
            if (_tag == null)
            {
                return;                 /* Oups */
            }
            if (!(_tag is NfcTag))
            {
                return;                 /* Oups */
            }
            NfcTag tag = _tag as NfcTag;

            if (!tag.IsFormatted() && !tag.Format())
            {
                this.BeginInvoke(new OnErrorInvoker(OnError), "This application has been unable to format the Tag", "Failed to encode the NFC Tag");
                return;
            }

            if (!tag.Write())
            {
                this.BeginInvoke(new OnErrorInvoker(OnError), "This application has been unable to write onto the Tag", "Failed to encode the NFC Tag");
                return;
            }

            if (cbLock.Visible && cbLock.Checked)
            {
                /* Try to lock the Tag */
                if (tag.IsLockable())
                {
                    if (!tag.Lock())
                    {
                        this.BeginInvoke(new OnErrorInvoker(OnError), "This application has been unable to lock the Tag in read-only state", "Failed to encode the NFC Tag");
                        return;
                    }
                }
                else
                {
                    /* This Tag is not locackable */
                    this.BeginInvoke(new OnErrorInvoker(OnError), "The Tag has been successfully written, but there's no method to put it in read-only state", "This NFC Tag can't be locked");
                    return;
                }
            }

            /* Done */
            this.BeginInvoke(new OnTagWriteInvoker(OnTagWrite), tag);
        }
Example #17
0
 /// <summary>
 /// Retrieves NFC Tag information.
 /// </summary>
 /// <param name="type">The Tag type</param>
 /// <param name="support">Whether or not to support NDEF messages</param>
 /// <param name="size">Stored NDEF message size in Tag</param>
 /// <param name="maxSize">Maximum NDEF message size that can be stored in Tag</param>
 /// <returns>Returns true if tag type was successfully obtained, false otherwise</returns>
 public bool GetTagType(ref string type, ref bool support, ref uint size, ref uint maxSize)
 {
     try
     {
         NfcTag nfcTag = NfcTagAdapter.GetConnectedTag();
         type    = nfcTag.Type.ToString();
         support = nfcTag.IsSupportNdef;
         size    = nfcTag.NdefSize;
         maxSize = nfcTag.MaximumNdefSize;
         return(true);
     }
     catch (Exception e)
     {
         LogImplementation.DLog("Failed get Tag Type " + e.Message);
         return(false);
     }
 }
Example #18
0
 private void btPoll_Click(object sender, EventArgs e)
 {
     try
     {
         UInt16 sysCode = UInt16.Parse(tbSysCode.Text, NumberStyles.HexNumber);
         card = nfclib.Polling(sysCode);
         if (card != null)
         {
             tbCard.Text = card.CardType.ToString() + ":"
                           + Utility.ByteToHex(card.Uid, 0, card.Uid.Length);
         }
         else
         {
             tbCard.Text = "未検出";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #19
0
        /*
         * card_read_proc
         * --------------
         * This is the core function to try read a card, and maybe recognize it as an NFC tag
         * The function is executed in a background thread, so the application's window keeps
         * responding during the dialog
         */
        private void card_read_proc()
        {
            NfcTag tag = null;
            string msg = null;
            bool   Desfire_formatable = false;

            Trace.WriteLine("Is the card a NFC Forum Tag ???");

            /*
             * 1st step, is the card a NFC Forum Tag ?
             * ---------------------------------------
             */


            if (!NfcTag.Recognize(cardchannel, out tag, out msg, out Desfire_formatable))
            {
                Trace.WriteLine("Unrecognized or unsupported tag");
            }


            /*
             * 2nd step, tell the application we've got something, and die
             * -----------------------------------------------------------
             */

            if (tag != null)
            {
                this.BeginInvoke(new OnTagReadInvoker(OnTagRead), tag);
            }
            else
            {
                if (Desfire_formatable)
                {
                    this.BeginInvoke(new EnableFormatButtonInvoker(EnableFormatButton));
                }

                this.BeginInvoke(new OnErrorInvoker(OnError), msg, "This is not a valid NFC Tag");
            }
        }
 private async void OnTagConnected(object sender, NfcTag e)
 {
     var text = _nfcScannerService.ReadNdefMessage(e.NdefMessage);
     await _pageDialogService.DisplayAlertAsync("Tag Content", text[0], null, "ok");
 }
Example #21
0
        /// <summary>
        /// 二维码生成
        /// </summary>
        /// <param name="strHZ"></param>
        /// <param name="strGoodsName"></param>
        /// <param name="strQty"></param>
        public void GetImg(string strHZ, string strGoodsName, string strQty, string strGoodsCode, string strBatch, string strBarcode)
        {
            try
            {
                b2d    = new Bmp2Bmp2Data();
                nfcTag = new NfcTag(new WI());

                string strPath = Application.StartupPath + "\\img\\" + strHZ + ".bmp";

                strHZ = "物料:" + strGoodsCode + ",批次:" + strBatch + ",数量:" + strQty + ",单号:" + Globels.strOrderNo + "," + strBarcode;
                int    nLen     = strHZ.Length;
                byte[] fileData = Encoding.GetEncoding("GB2312").GetBytes(strHZ);
                int    nLen2    = fileData.Length;

                Barcode.Make(fileData, nLen2, 0, 0, 0, strPath, 2);
                Thread.Sleep(100);
                FileStream fs     = new FileStream(strPath, FileMode.Open, FileAccess.Read);
                Byte[]     mybyte = new byte[fs.Length];
                fs.Read(mybyte, 0, mybyte.Length);
                fs.Close();

                MemoryStream ms     = new MemoryStream(mybyte);
                Bitmap       myimge = new Bitmap(ms);

                Bitmap   image = new Bitmap(296, 128);                                //初始化大小
                Graphics g     = Graphics.FromImage(image);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置图片质量

                g.Clear(Color.White);
                g.DrawImage(myimge, 190, 15, 80, 80);
                Font  f1 = new Font("Arial ", 40); //, System.Drawing.FontStyle.Bold);//设置字体样式,大小
                Font  f2 = new Font("Arial ", 30); //, System.Drawing.FontStyle.Bold);//设置字体样式,大小
                Font  f3 = new Font("Arial ", 12); //, System.Drawing.FontStyle.Bold);//设置字体样式,大小
                Font  f4 = new Font("Arial ", 10); //, System.Drawing.FontStyle.Bold);//设置字体样式,大小
                Brush b  = new SolidBrush(Color.Black);
                Brush r  = new SolidBrush(Color.White);
                //g.DrawString(strHZ, f3, b, 15, 60);//设置位置

                g.DrawString("名称:" + strGoodsName, f4, b, 4, 10);     //设置位置
                g.DrawString("数量:" + strQty, f4, b, 4, 30);           //设置位置
                g.DrawString("保质期:" + "24小时", f4, b, 4, 50);          //设置位置
                g.DrawString("负责人:" + Globels.strName, f4, b, 4, 70); //设置位置
                //g.DrawString("订单:" + comOrderNo.Text, f4, b, 4, 90);//设置位置

                g.DrawString("日期:" + DateTime.Now.ToString("yyyy-MM-dd"), f4, b, 178, 105); //设置位置

                image.Save(strPath, ImageFormat.Jpeg);                                      //自己创建一个文件夹,放入生成的图片(根目录下)

                //二维码图片nfc写入
                bp = new Bmp2BmpProduct(new TagViewSize((EnumTagViewSizeID)(0x21), 0x00),
                                        new Bitmap(image)
                                        );
                b2d.ImageYuLan(bp);

                byte[] _nfcTagBmpData       = b2d.GetDataToSend(bp);
                int    _nfcTagBmpDataLength = b2d.SendLength;

                nfcTag.SendBmp2NfcTag(_nfcTagBmpData, _nfcTagBmpDataLength);

                //MessageBox.Show("OK");
            }
            catch (Exception ex)
            {
                //untCommon.ErrorMsg("二维码生成异常!:" + ex.Message);
                lblTS.Text = "系统提示:" + "二维码生成异常!:" + ex.Message;
            }
        }
Example #22
0
 public NfcReader()
 {
     _nfcTag = new NfcTag();
 }
Example #23
0
 public NfcScannerService()
 {
     _nfcTag = new NfcTag();
 }
Example #24
0
 private void frmMeatProcessList_Load(object sender, EventArgs e)
 {
     b2d    = new Bmp2Bmp2Data();
     nfcTag = new NfcTag(new WI());
 }
Example #25
0
 void OnTagWrite(NfcTag _tag)
 {
     MessageBox.Show("Writing tag OK", "Operation succesful", MessageBoxButtons.OK, MessageBoxIcon.Information);
     Trace.WriteLine("Write OK");
 }
Example #26
0
        void BtnWriteClick(object sender, EventArgs e)
        {
            if (control == null)
            {
                return;
            }

            NfcTag nfcTag = null;

            SCardChannel channel = new SCardChannel(reader);

            if (!channel.Connect())
            {
                MessageBox.Show("Failed to connect to the card.");
                return;
            }

            if (rbType2.Checked)
            {
                if (NfcTagType2.Recognize(channel))
                {
                    Trace.WriteLine("This card is a NFC type 2 Tag");
                    nfcTag = NfcTagType2.Create(channel);
                }
                else
                {
                    Trace.WriteLine("This card is not a NFC type 2 Tag, sorry");
                }
            }
            else
            if (rbType4.Checked)
            {
                if (NfcTagType4.Recognize(channel))
                {
                    Trace.WriteLine("This card is a NFC type 4 Tag");
                    nfcTag = NfcTagType4.Create(channel);
                }
                else
                {
                    Trace.WriteLine("This card is not a NFC type 4 Tag, sorry");
                }
            }

            if (nfcTag == null)
            {
                channel.Disconnect();
                MessageBox.Show("This card is not supported. Are you sure the emulution mode is running?");
                return;
            }

            if (!nfcTag.IsFormatted())
            {
                channel.Disconnect();
                MessageBox.Show("The card is not formatted as a NFC Tag.");
                return;
            }

            nfcTag.Content.Clear();

            Ndef ndef = control.GetContent();

            nfcTag.Content.Add(ndef);

            if (!nfcTag.Write(true))
            {
                channel.Disconnect();
                MessageBox.Show("Failed to write the NFC Tag.");
                return;
            }

            channel.Disconnect();
        }
        void OnTagRead(NfcTag tag)
        {
            try
            {
                string msg;
                _tag         = tag;
                _studentData = null;

                if (_tag == null)
                {
                    msg = "Internal error, The Tag is Invalid!";
                    WarnNotify("Warning|" + msg);
                    return;
                }

                if ((tag.Content == null) || (tag.Content.Count == 0))
                {
                    if (!tag.IsLocked())
                    {
                        msg = "The Device has no valid content yet. You may proceed with Tag Writting.";
                        WarnNotify("Warning|" + msg);
                    }
                    else
                    {
                        msg = "The Tag has no valid content, but is not writable";
                        WarnNotify("Warning|" + msg);
                    }
                }
                else
                {
                    var ndef = tag.Content.FirstOrDefault();
                    switch (ndef)
                    {
                    case null:
                        msg = "This Tag is Empty.";
                        WarnNotify("Warning|" + msg);
                        return;

                    case RtdSmartPoster smart:
                        using (var localEntities = new LocalEntities())
                        {
                            var matricNumber = smart.Title.FirstOrDefault()?.Value ?? "";
                            _studentData =
                                localEntities.Student_ProfileData.FirstOrDefault(x =>
                                                                                 x.MatricNumber == matricNumber && x.TagId == _tagUID);

                            msg = _studentData == null
                                    ? "No Student Record, Access Denied."
                                    : $"{_studentData.FirstName} {_studentData.LastName}, Access Granted";

                            var speak = new SpeechSynthesizer();
                            speak.SpeakAsync(msg);
                        }

                        SuccessNotify("Awesome|" + msg);
                        break;

                    default:
                        msg = "Data found but its not an EdBoxPremium Data.";
                        WarnNotify("Warning|" + msg);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
        void ReaderStatusChanged(uint readerState, CardBuffer cardAtr)
        {
            try
            {
                string msg;

                if (InvokeRequired)
                {
                    this.BeginInvoke(new ReaderStatusChangedInvoker(ReaderStatusChanged), readerState, cardAtr);
                    return;
                }

                SCARD.ReaderStatusToString(readerState);

                if (cardAtr != null)
                {
                    _tagATR = RemoveSpaces(cardAtr.AsString(" "));
                }
                else
                {
                }

                if (readerState == SCARD.STATE_UNAWARE)
                {
                    if (_cardchannel != null)
                    {
                        _cardchannel.Disconnect();
                        _cardchannel = null;
                    }

                    if (!_inLoop)
                    {
                        msg = "The reader we were working with has gone AWOL from the system.";
                        WarnNotify("Warning|" + msg);
                        _inLoop = true;
                    }

                    tmrTagMonitor.Enabled = true;
                    msg = "Reader not Found. Please check Connection.";
                    WarnNotify("Warning|" + msg);
                }
                else if ((readerState & SCARD.STATE_EMPTY) != 0)
                {
                    _tag    = null;
                    _inLoop = false;

                    _studentData = null;
                    InfoNotify("Ready|Please insert another card for Tagging");

                    if (_cardchannel == null)
                    {
                        return;
                    }

                    _cardchannel.Disconnect();
                    _cardchannel = null;
                }
                else if ((readerState & SCARD.STATE_UNAVAILABLE) != 0)
                {
                }
                else if ((readerState & SCARD.STATE_MUTE) != 0)
                {
                }
                else if ((readerState & SCARD.STATE_INUSE) != 0)
                {
                    _inLoop = false;
                }
                else if ((readerState & SCARD.STATE_PRESENT) != 0)
                {
                    _inLoop = false;
                    if (_cardchannel != null)
                    {
                        return;
                    }

                    _cardchannel = new SCardChannel(DeviceManager.DeviceSpec.Nfc);

                    if (_cardchannel.Connect())
                    {
                        var mifare = new MiFareCardProg();
                        _tagUID = RemoveSpaces(mifare.GetUID(DeviceManager.DeviceSpec.Nfc).Trim());

                        _cardthread = new Thread(card_read_proc);
                        _cardthread.Start();
                    }
                    else
                    {
                        msg =
                            "NearField failed to connect to the card in the reader. Check that you don't have another application running in background that tries to work with the smartcards in the same time as NearField";
                        WarnNotify("Warning|" + msg);
                        _cardchannel = null;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
Example #29
0
        void OnTagRead(NfcTag _tag)
        {
            tag = _tag;

            Trace.WriteLine("Read terminated");

            if (tag == null)
            {
                MessageBox.Show("Internal error, tag is null!");
                return;
            }

            if ((tag.Content == null) || (tag.Content.Count == 0))
            {
                if (!tag.IsLocked())
                {
                    MessageBox.Show("The Tag has no valid content yet. You may create your own content and write it onto the tag", "This NFC Tag is empty");
                    setEditable(true);
                }
                else
                {
                    MessageBox.Show("The Tag has no valid content, but is not writable", "This NFC Tag is empty");
                }
            }
            else
            {
                Unselect();

                for (int i = 0; i < tag.Content.Count; i++)
                {
                    /* Display the first record we support in the tag's content */
                    Ndef ndef = tag.Content[i];

                    if (ndef is RtdSmartPoster)
                    {
                        SelectSmartPoster();
                    }
                    else
                    if (ndef is RtdUri)
                    {
                        SelectUri();
                    }
                    else
                    if (ndef is RtdText)
                    {
                        SelectText();
                    }
                    else
                    if (ndef is RtdVCard)
                    {
                        SelectVCard();
                    }
                    else
                    if (ndef is RtdMedia)
                    {
                        SelectMedia();
                    }
                    else
                    if (ndef is RtdHandoverSelector)
                    {
                        SelectWifiHandover();
                    }

                    if (control != null)
                    {
                        control.SetContent(ndef);
                        break;
                    }
                }

                if (!tag.IsLocked())
                {
                    /* It will be possible to rewrite the tag */
                    setEditable(true);
                }

                if (control == null)
                {
                    /* No supported record has been found */
                    Unselect();
                    MessageBox.Show("This Tag contains a valid content, but this application doesn't know how to display it", "This NFC Tag is not supported");
                }
            }
        }
Example #30
0
        private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
        {

            var bytes = message.Data.ToArray();
            List<NdefRecord> records = Ndef.parse(bytes);

            NfcTag tag = new NfcTag(records);

           // calling a global js method to fire an nfc event
           ScriptCallback script = new ScriptCallback("fireNfcTagEvent", new string[] { "ndef", JsonHelper.Serialize(tag) });
           this.InvokeCustomScript(script, false);
        }