コード例 #1
0
 string GetRecords(NFCNdefPayload[] records)
 {
     string record = null;
     var results = new NFCNdefRecord[records.Length];
     for (var i = 0; i < records.Length; i++)
     {
         record = records[i].Payload.ToString();                
     }
     return record;
 }
コード例 #2
0
        string GetMessage(NFCNdefRecord record)
        {
            var message = $"Message: {record.Message}";

            message += Environment.NewLine;
            message += $"RawMessage: {Encoding.UTF8.GetString(record.Payload)}";
            message += Environment.NewLine;
            message += $"Type: {record.TypeFormat.ToString()}";

            if (!string.IsNullOrWhiteSpace(record.MimeType))
            {
                message += Environment.NewLine;
                message += $"MimeType: {record.MimeType}";
            }

            return(message);
        }
コード例 #3
0
        private static void SendData(ITagInfo tagInfo, bool format)
        {
            try
            {
                ITagInfo info = tagInfo;

                List <NFCNdefRecord> records = new List <NFCNdefRecord>();

                NFCNdefRecord record = new NFCNdefRecord()
                {
                    MimeType = "", TypeFormat = NFCNdefTypeFormat.WellKnown, Payload = Encoding.ASCII.GetBytes(currentMessage)
                };

                records.Add(record);

                info.Records = records.ToArray();
                CrossNFC.Current.PublishMessage(info, makeReadOnly: false);
            }
            catch (Exception ex)
            {
                //Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "Ok");
            }
        }
コード例 #4
0
        async void Current_OnTagDiscovered(ITagInfo tagInfo, bool format)
        {
            if (!CrossNFC.Current.IsWritingTagSupported)
            {
                await ShowAlert("Writing tag is not supported on this device");

                return;
            }

            try
            {
                var record = new NFCNdefRecord
                {
                    TypeFormat = NFCNdefTypeFormat.Mime,
                    MimeType   = MIME_TYPE,
                    Payload    = NFCUtils.EncodeToByteArray("Hi Buddy!")
                                 //TypeFormat = NFCNdefTypeFormat.Uri,
                                 //Payload = NFCUtils.EncodeToByteArray("http://google.fr")
                };

                tagInfo.Records = new[] { record };

                if (format)
                {
                    CrossNFC.Current.ClearMessage(tagInfo);
                }
                else
                {
                    CrossNFC.Current.PublishMessage(tagInfo);
                }
            }
            catch (System.Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }
コード例 #5
0
        void Current_OnTagDiscovered(ITagInfo tagInfo, bool format)
        {
            try
            {
                if (!CrossNFC.Current.IsWritingTagSupported)
                {
                    return;
                }

                try
                {
                    NFCNdefRecord record = null;
                    switch (_type)
                    {
                    case NFCNdefTypeFormat.WellKnown:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.WellKnown,
                            MimeType   = MIME_TYPE,
                            Payload    = NFCUtils.EncodeToByteArray("Plugin.NFC is awesome!")
                        };
                        break;

                    case NFCNdefTypeFormat.Uri:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.Uri,
                            Payload    = NFCUtils.EncodeToByteArray("https://github.com/franckbour/Plugin.NFC")
                        };
                        break;

                    case NFCNdefTypeFormat.Mime:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.Mime,
                            MimeType   = MIME_TYPE,
                            Payload    = NFCUtils.EncodeToByteArray("Plugin.NFC is awesome!")
                        };
                        break;

                    default:
                        break;
                    }

                    if (!format && record == null)
                    {
                        throw new Exception("Record can't be null.");
                    }

                    tagInfo.Records = new[] { record };

                    if (format)
                    {
                        CrossNFC.Current.ClearMessage(tagInfo);
                    }
                    else
                    {
                        CrossNFC.Current.PublishMessage(tagInfo, _makeReadOnly);
                    }
                }
                catch (System.Exception ex)
                {
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #6
0
        async void Current_OnTagDiscovered(ITagInfo tagInfo, bool format)
        {
            try
            {
                if (!CrossNFC.Current.IsWritingTagSupported)
                {
                    await DisplayAlert("Alert", "Writing tag not supported on this device", "Ok");

                    return;
                }

                try
                {
                    NFCNdefRecord record = null;
                    switch (_type)
                    {
                    case NFCNdefTypeFormat.WellKnown:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.WellKnown,
                            MimeType   = MonthlyPassCashPaymentPage.MIME_TYPE,
                            Payload    = NFCUtils.EncodeToByteArray("Plugin.NFC is awesome!")
                        };
                        break;

                    case NFCNdefTypeFormat.Uri:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.Uri,
                            Payload    = NFCUtils.EncodeToByteArray("https://github.com/franckbour/Plugin.NFC")
                        };
                        break;

                    case NFCNdefTypeFormat.Mime:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.Mime,
                            MimeType   = MonthlyPassCashPaymentPage.MIME_TYPE,
                            Payload    = NFCUtils.EncodeToByteArray("Plugin.NFC is awesome!")
                        };
                        break;

                    default:
                        break;
                    }

                    if (!format && record == null)
                    {
                        throw new Exception("Record can't be null.");
                    }

                    tagInfo.Records = new[] { record };

                    if (format)
                    {
                        CrossNFC.Current.ClearMessage(tagInfo);
                    }
                    else
                    {
                        CrossNFC.Current.PublishMessage(tagInfo, _makeReadOnly);
                    }
                }
                catch (System.Exception ex)
                {
                    await DisplayAlert("Alert", ex.Message, "Ok");
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Alert", "Unable to proceed,Please contact Admin" + ex.Message, "Ok");
            }
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: jtorvald/Plugin.NFC
        async void Current_OnTagDiscovered(ITagInfo tagInfo, bool format)
        {
            if (!CrossNFC.Current.IsWritingTagSupported)
            {
                await ShowAlert("Writing tag is not supported on this device");

                return;
            }

            try
            {
                NFCNdefRecord record = null;
                switch (_type)
                {
                case NFCNdefTypeFormat.WellKnown:
                    record = new NFCNdefRecord
                    {
                        TypeFormat = NFCNdefTypeFormat.WellKnown,
                        MimeType   = MIME_TYPE,
                        Payload    = NFCUtils.EncodeToByteArray("This is a text message!")
                    };
                    break;

                case NFCNdefTypeFormat.Uri:
                    record = new NFCNdefRecord
                    {
                        TypeFormat = NFCNdefTypeFormat.Uri,
                        Payload    = NFCUtils.EncodeToByteArray("https://google.fr")
                    };
                    break;

                case NFCNdefTypeFormat.Mime:
                    record = new NFCNdefRecord
                    {
                        TypeFormat = NFCNdefTypeFormat.Mime,
                        MimeType   = MIME_TYPE,
                        Payload    = NFCUtils.EncodeToByteArray("This is a custom record!")
                    };
                    break;

                default:
                    break;
                }

                if (!format && record == null)
                {
                    throw new Exception("Record can't be null.");
                }

                tagInfo.Records = new[] { record };

                if (format)
                {
                    CrossNFC.Current.ClearMessage(tagInfo);
                }
                else
                {
                    CrossNFC.Current.PublishMessage(tagInfo);
                }
            }
            catch (System.Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }
コード例 #8
0
        void Current_OnTagDiscovered(ITagInfo tagInfo, bool format)
        {
            try
            {
                if (!CrossNFC.Current.IsWritingTagSupported)
                {
                    DisplayAlert("Alert", "Writing tag not supported on this device", "Ok");
                    return;
                }

                try
                {
                    NFCNdefRecord record = null;
                    switch (_type)
                    {
                    case NFCNdefTypeFormat.WellKnown:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.WellKnown,
                            MimeType   = MIME_TYPE,
                            Payload    = NFCUtils.EncodeToByteArray("Plugin.NFC is awesome!")
                        };
                        break;

                    case NFCNdefTypeFormat.Uri:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.Uri,
                            Payload    = NFCUtils.EncodeToByteArray("https://github.com/franckbour/Plugin.NFC")
                        };
                        break;

                    case NFCNdefTypeFormat.Mime:
                        record = new NFCNdefRecord
                        {
                            TypeFormat = NFCNdefTypeFormat.Mime,
                            MimeType   = MIME_TYPE,
                            Payload    = NFCUtils.EncodeToByteArray("Plugin.NFC is awesome!")
                        };
                        break;

                    default:
                        break;
                    }

                    if (!format && record == null)
                    {
                        throw new Exception("Record can't be null.");
                    }

                    tagInfo.Records = new[] { record };

                    if (format)
                    {
                        CrossNFC.Current.ClearMessage(tagInfo);
                    }
                    else
                    {
                        CrossNFC.Current.PublishMessage(tagInfo, _makeReadOnly);
                    }
                }
                catch (System.Exception ex)
                {
                    DisplayAlert("Alert", ex.Message, "Ok");
                }
            }
            catch (Exception ex)
            {
                DisplayAlert("Alert", "Unable to proceed,Please contact Admin" + ex.Message, "Ok");
                dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message, "MasterDetailHomePage.xaml.cs", "", "Current_OnTagDiscovered");
            }
        }