Exemple #1
0
        private void ManageWriteMimeOperation()
        {
            NfcNdefRecord record = new NfcNdefRecord
            {
                TypeFormat = NfcNdefTypeFormat.Mime,
                Payload    = NfcUtils.EncodeToByteArray(mimeToWrite)
            };

            OnNfcTagMimeWriten?.Invoke(this, WriteNfcNdefRecord(record));
        }
Exemple #2
0
        private void ManageWriteUriOperation()
        {
            NfcNdefRecord record = new NfcNdefRecord
            {
                TypeFormat = NfcNdefTypeFormat.Uri,
                Payload    = NfcUtils.EncodeToByteArray(uriToWrite)
            };

            OnNfcTagUriWriten?.Invoke(this, WriteNfcNdefRecord(record));
        }
Exemple #3
0
        private void ManageWriteTextOperation()
        {
            NfcNdefRecord record = new NfcNdefRecord
            {
                TypeFormat = NfcNdefTypeFormat.WellKnown,
                Payload    = NfcUtils.EncodeToByteArray(textToWrite),
            };

            OnNfcTagTextWriten?.Invoke(this, WriteNfcNdefRecord(record));
        }
        public async Task InitializeAsync()
        {
            // First try to find a reader that advertises as being NFC
            var deviceInfo = await SmartCardReaderUtils.GetFirstSmartCardReaderInfo(SmartCardReaderKind.Nfc);

            if (deviceInfo == null)
            {
                // If we didn't find an NFC reader, let's see if there's a "generic" reader meaning we're not sure what type it is
                deviceInfo = await SmartCardReaderUtils.GetFirstSmartCardReaderInfo(SmartCardReaderKind.Any);
            }

            if (deviceInfo == null)
            {
                LogMessage("NFC card reader mode not supported on this device", NotifyType.ErrorMessage);
                return;
            }

            if (!deviceInfo.IsEnabled)
            {
                var msgbox = new Windows.UI.Popups.MessageDialog("Your NFC proximity setting is turned off, you will be taken to the NFC proximity control panel to turn it on");
                msgbox.Commands.Add(new Windows.UI.Popups.UICommand("OK"));
                await msgbox.ShowAsync();

                // This URI will navigate the user to the NFC proximity control panel
                NfcUtils.LaunchNfcProximitySettingsPage();
                return;
            }

            if (m_cardReader == null)
            {
                m_cardReader = await SmartCardReader.FromIdAsync(deviceInfo.Id);

                m_cardReader.CardAdded   += cardReader_CardAdded;
                m_cardReader.CardRemoved += cardReader_CardRemoved;
            }

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\Data\StationCode.csv";

            m_stationCodeList = await Core.Models.StationCodeData.LoadAsync(path);
        }
Exemple #5
0
        private bool CheckWriteOperation(Ndef ndef, NfcNdefRecord record)
        {
            //TODO 3. WRITING CARD 6
            if (ndef == null)
            {
                return(false);
            }

            if (!ndef.IsWritable)
            {
                Debug.WriteLine("NFC tag is readonly");
                return(false);
            }

            if (ndef.MaxSize < NfcUtils.GetSize(new NfcNdefRecord[] { record }))
            {
                Debug.WriteLine("NFC tag size is less than the message to write");
                return(false);
            }

            return(true);
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            // First try to find a reader that advertises as being NFC
            var deviceInfo = await SmartCardReaderUtils.GetFirstSmartCardReaderInfo(SmartCardReaderKind.Nfc);

            if (deviceInfo == null)
            {
                // If we didn't find an NFC reader, let's see if there's a "generic" reader meaning we're not sure what type it is
                deviceInfo = await SmartCardReaderUtils.GetFirstSmartCardReaderInfo(SmartCardReaderKind.Any);
            }

            if (deviceInfo == null)
            {
                LogMessage("NFC card reader mode not supported on this device");
                return;
            }

            if (!deviceInfo.IsEnabled)
            {
                var msgbox = new Windows.UI.Popups.MessageDialog("Your NFC proximity setting is turned off, you will be taken to the NFC proximity control panel to turn it on");
                msgbox.Commands.Add(new Windows.UI.Popups.UICommand("OK"));
                await msgbox.ShowAsync();

                // This URI will navigate the user to the NFC proximity control panel
                NfcUtils.LaunchNfcProximitySettingsPage();
                return;
            }

            if (m_cardReader == null)
            {
                m_cardReader = await SmartCardReader.FromIdAsync(deviceInfo.Id);

                m_cardReader.CardAdded   += cardReader_CardAdded;
                m_cardReader.CardRemoved += cardReader_CardRemoved;
            }
        }