Ejemplo n.º 1
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     var device = ProximityDevice.GetDefault();
     if (device == null) return;
     var record = new NdefSpRecord {
         Uri = "cloudsdale://clouds/" + cloud.id,
         NfcAction = NdefSpActRecord.NfcActionType.DoAction
     };
     record.AddTitle(new NdefTextRecord { Text = cloud.name, LanguageCode = "en" });
     var message = new NdefMessage { record };
     messageIds.Add(device.PublishBinaryMessage("NDEF", message.ToByteArray().AsBuffer()));
 }
Ejemplo n.º 2
0
        // ------------------------------------------
        //  PRIVATE READER
        // ------------------------------------------
        private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
        {
            // Parse raw byte array to NDEF message
              var rawMsg = message.Data.ToArray();
              var ndefMessage = NdefMessage.FromByteArray(rawMsg);

              // Loop over all records contained in the NDEF message
              foreach (NdefRecord record in ndefMessage) {
            Console.WriteLine("Record type: " + Encoding.UTF8.GetString(record.Type, 0, record.Type.Length));

            // Check the type of each record - handling a Smart Poster in this example
            var specializedType = record.CheckSpecializedType(true);

            // Convert and extract Smart Poster info
            if (specializedType == typeof(NdefSpRecord)) {
              var spRecord = new NdefSpRecord(record);
              String msg = "URI: " + spRecord.Uri + "\n"
                         + "Titles: " + spRecord.TitleCount() + "\n"
                         + "1. Title: " + spRecord.Titles[0].Text + "\n"
                         + "Action set: " + spRecord.ActionInUse();
              NFCManager.getInstance().Alert(msg);
            }

            // Convert and extract URI record info
            else if (specializedType == typeof(NdefUriRecord)) {
              var uriRecord = new NdefUriRecord(record);
              String msg = "URI: " + uriRecord.Uri + "\n";
              NFCManager.getInstance().Alert(msg);
              NFCManager.getInstance().SendRequest(uriRecord.Uri);
            }

            // Convert and extract Mailto record info
            else if (specializedType == typeof(NdefMailtoRecord)) {
              var mailtoRecord = new NdefMailtoRecord(record);
              String msg = "Address: " + mailtoRecord.Address + "\n"
                     + "Subject: " + mailtoRecord.Subject + "\n"
                     + "Body: " + mailtoRecord.Body;
              NFCManager.getInstance().Alert(msg);
            }
              }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Mailto record.
 /// Checks the type and type name format and if the URI starts with the correct scheme.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Mailto record, false if it's a different record.</returns>
 public new static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null)
     {
         return(false);
     }
     if (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Payload != null)
     {
         if (record.Type.SequenceEqual(NdefUriRecord.UriType))
         {
             var testRecord = new NdefUriRecord(record);
             return(testRecord.Uri.StartsWith(MailtoScheme));
         }
         if (record.Type.SequenceEqual(SmartPosterType))
         {
             var testRecord = new NdefSpRecord(record);
             return(testRecord.Uri.StartsWith(MailtoScheme));
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        private void Device_DeviceArrived(ProximityDevice sender)
        {
            var data = new { Employee = new { Id = 2572923226000L, Name = "TestUser" } };
            var payload = JsonConvert.SerializeObject(data);

            var spRecord = new NdefSpRecord
            {
                NfcAction = NdefSpActRecord.NfcActionType.OpenForEditing,
                Payload = Encoding.UTF8.GetBytes(payload),
                NfcSize = (uint)payload.Length,
                Type = Encoding.UTF8.GetBytes("application/json; charset=\"utf-8\"")
            };

            var msg = new NdefMessage { spRecord };

            long publishingId = device.PublishBinaryMessage("NDEF:WriteTag", msg.ToByteArray().AsBuffer(), (d0, id) => {
                device.DeviceArrived -= Device_DeviceArrived;
                Debug.WriteLine(" published. id = " + id);
                var notify = new MessageDialog("The message has been published.");
            });
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Dynamically construct some more NDEF records
            var spRecord = new NdefSpRecord
            {
                Uri = "http://andijakl.github.io/ndef-nfc/",
                NfcAction = NdefSpActRecord.NfcActionType.DoAction
            };
            spRecord.AddTitle(new NdefTextRecord { LanguageCode = "en", Text = "NFC Library" });
            spRecord.AddTitle(new NdefTextRecord { LanguageCode = "de", Text = "NFC Bibliothek" });
            NfcRecords.Add("SmartPoster", spRecord);

            // Ensure the path exists
            var tagsDirectory = Path.Combine(Environment.CurrentDirectory, FileDirectory);
            Directory.CreateDirectory(tagsDirectory);

            // Write tag contents to files
            foreach (var curNdefRecord in NfcRecords)
            {
                WriteTagFile(tagsDirectory, curNdefRecord.Key, curNdefRecord.Value);
            }

            // Multi-record file
            var record1 = new NdefUriRecord {Uri = "http://www.twitter.com"};
            var record2 = new NdefAndroidAppRecord {PackageName = "com.twitter.android"};
            var twoRecordsMsg = new NdefMessage {record1, record2};
            WriteTagFile(tagsDirectory, "TwoRecords", twoRecordsMsg);

            var record3 = new NdefRecord
            {
                TypeNameFormat = NdefRecord.TypeNameFormatType.ExternalRtd,
                Type = Encoding.UTF8.GetBytes("custom.com:myapp")
            };
            var threeRecordsMsg = new NdefMessage { record1, record3, record2 };
            WriteTagFile(tagsDirectory, "ThreeRecords", threeRecordsMsg);

            // Success message on output
            Console.WriteLine("Generated {0} tag files in {1}.", NfcRecords.Count, tagsDirectory);
            Debug.WriteLine("Generated {0} tag files in {1}.", NfcRecords.Count, tagsDirectory);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Telephone record.
 /// Checks the type and type name format and if the URI starts with the correct scheme.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Telephone record, false if it's a different record.</returns>
 public static new bool IsRecordType(NdefRecord record)
 {
     if (record.Type == null) return false;
     if (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Payload != null)
     {
         if (record.Type.SequenceEqual(NdefUriRecord.UriType))
         {
             var testRecord = new NdefUriRecord(record);
             return testRecord.Uri.StartsWith(TelScheme);
         }
         if (record.Type.SequenceEqual(SmartPosterType))
         {
             var testRecord = new NdefSpRecord(record);
             return testRecord.Uri.StartsWith(TelScheme);
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Checks the type name format and type of this record and returns
 /// the appropriate specialized class, if one is available and known
 /// for this record type.
 /// </summary>
 /// <param name="checkForSubtypes">If set to true, also checks for
 /// subtypes of the URL / SmartPoster record where the library offers
 /// a convenient handling class - e.g. for SMS or Mailto records,
 /// which are actually URL schemes.</param>
 /// <returns>Type name of the specialized class that can understand
 /// and manipulate the payload through convenience methods.</returns>
 public Type CheckSpecializedType(bool checkForSubtypes)
 {
     // Note: can't check for specialized types like the geo record
     // or the SMS record yet, as these are just convenience classes
     // for creating URI / Smart Poster records.
     if (checkForSubtypes)
     {
         // Need to check specialized URI / Sp records before checking for base types.
         if (NdefSmsRecord.IsRecordType(this))
         {
             return(typeof(NdefSmsRecord));
         }
         if (NdefMailtoRecord.IsRecordType(this))
         {
             return(typeof(NdefMailtoRecord));
         }
         if (NdefTelRecord.IsRecordType(this))
         {
             return(typeof(NdefTelRecord));
         }
         if (NdefWindowsSettingsRecord.IsRecordType(this))
         {
             return(typeof(NdefWindowsSettingsRecord));
         }
     }
     // Unique / base record types
     if (NdefUriRecord.IsRecordType(this))
     {
         return(typeof(NdefUriRecord));
     }
     if (NdefSpRecord.IsRecordType(this))
     {
         return(typeof(NdefSpRecord));
     }
     if (NdefTextRecord.IsRecordType(this))
     {
         return(typeof(NdefTextRecord));
     }
     if (NdefSpActRecord.IsRecordType(this))
     {
         return(typeof(NdefSpActRecord));
     }
     if (NdefSpSizeRecord.IsRecordType(this))
     {
         return(typeof(NdefSpSizeRecord));
     }
     if (NdefSpMimeTypeRecord.IsRecordType(this))
     {
         return(typeof(NdefSpMimeTypeRecord));
     }
     if (NdefLaunchAppRecord.IsRecordType(this))
     {
         return(typeof(NdefLaunchAppRecord));
     }
     if (NdefAndroidAppRecord.IsRecordType(this))
     {
         return(typeof(NdefAndroidAppRecord));
     }
     if (NdefVcardRecordBase.IsRecordType(this))
     {
         return(typeof(NdefVcardRecordBase));
     }
     if (NdefIcalendarRecordBase.IsRecordType(this))
     {
         return(typeof(NdefIcalendarRecordBase));
     }
     if (NdefBtSecureSimplePairingRecord.IsRecordType(this))
     {
         return(typeof(NdefBtSecureSimplePairingRecord));
     }
     if (NdefHandoverSelectRecord.IsRecordType(this))
     {
         return(typeof(NdefHandoverSelectRecord));
     }
     if (NdefHandoverErrorRecord.IsRecordType(this))
     {
         return(typeof(NdefHandoverErrorRecord));
     }
     if (NdefHandoverAlternativeCarrierRecord.IsRecordType(this))
     {
         return(typeof(NdefHandoverAlternativeCarrierRecord));
     }
     if (NdefMimeImageRecordBase.IsRecordType(this))
     {
         return(typeof(NdefMimeImageRecordBase));
     }
     return(typeof(NdefRecord));
 }
Ejemplo n.º 8
0
        private async Task ParseTagContents(NdefMessage ndefMessage, StringBuilder tagContents)
        {
            // Loop over all records contained in the NDEF message
            foreach (NdefRecord record in ndefMessage)
            {
                // --------------------------------------------------------------------------
                // Print generic information about the record
                if (record.Id != null && record.Id.Length > 0)
                {
                    // Record ID (if present)
                    tagContents.AppendFormat("Id: {0}\n", Encoding.UTF8.GetString(record.Id, 0, record.Id.Length));
                }
                // Record type name, as human readable string
                tagContents.AppendFormat("Type name: {0}\n", ConvertTypeNameFormatToString(record.TypeNameFormat));
                // Record type
                if (record.Type != null && record.Type.Length > 0)
                {
                    tagContents.AppendFormat("Record type: {0}\n",
                        Encoding.UTF8.GetString(record.Type, 0, record.Type.Length));
                }

                // --------------------------------------------------------------------------
                // Check the type of each record
                // Using 'true' as parameter for CheckSpecializedType() also checks for sub-types of records,
                // e.g., it will return the SMS record type if a URI record starts with "sms:"
                // If using 'false', a URI record will always be returned as Uri record and its contents won't be further analyzed
                // Currently recognized sub-types are: SMS, Mailto, Tel, Nokia Accessories, NearSpeak, WpSettings
                var specializedType = record.CheckSpecializedType(true);

                if (specializedType == typeof(NdefMailtoRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract Mailto record info
                    var mailtoRecord = new NdefMailtoRecord(record);
                    tagContents.Append("-> Mailto record\n");
                    tagContents.AppendFormat("Address: {0}\n", mailtoRecord.Address);
                    tagContents.AppendFormat("Subject: {0}\n", mailtoRecord.Subject);
                    tagContents.AppendFormat("Body: {0}\n", mailtoRecord.Body);
                }
                else if (specializedType == typeof(NdefUriRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract URI record info
                    var uriRecord = new NdefUriRecord(record);
                    tagContents.Append("-> URI record\n");
                    tagContents.AppendFormat("URI: {0}\n", uriRecord.Uri);
                }
                else if (specializedType == typeof(NdefSpRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract Smart Poster info
                    var spRecord = new NdefSpRecord(record);
                    tagContents.Append("-> Smart Poster record\n");
                    tagContents.AppendFormat("URI: {0}", spRecord.Uri);
                    tagContents.AppendFormat("Titles: {0}", spRecord.TitleCount());
                    if (spRecord.TitleCount() > 1)
                        tagContents.AppendFormat("1. Title: {0}", spRecord.Titles[0].Text);
                    tagContents.AppendFormat("Action set: {0}", spRecord.ActionInUse());
                    // You can also check the action (if in use by the record), 
                    // mime type and size of the linked content.
                }
                //else if (specializedType == typeof(NdefVcardRecordBase))
                //{
                //    // --------------------------------------------------------------------------
                //    // Convert and extract business card info
                //    var vcardRecord = new NdefVcardRecord(record);
                //    tagContents.Append("-> Business Card record" + Environment.NewLine);
                //    var contact = vcardRecord.ContactData;

                //    // Contact has phone or email info set? Use contact manager to show the contact card
                //    await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                //    {
                //        if (contact.Emails.Any() || contact.Phones.Any())
                //        {
                //            var rect = GetElementRect(StatusOutput);
                //            ContactManager.ShowContactCard(contact, rect, Placement.Below);
                //        }
                //        else
                //        {
                //            // No phone or email set - contact manager would not show the contact card.
                //            // -> parse manually
                //            tagContents.AppendFormat("Name: {0}\n", contact.DisplayName);
                //            tagContents.Append("[not parsing other values in the demo app]");
                //        }
                //    });
                //}
                //else if (specializedType == typeof(NdefIcalendarRecordBase))
                //{
                //    // --------------------------------------------------------------------------
                //    // Convert and extract iCalendar info
                //    var icalendarRecord = new NdefIcalendarRecord(record);
                //    tagContents.Append("-> iCalendar record" + Environment.NewLine);
                //    var ap = icalendarRecord.AppointmentData;
                //    if (!String.IsNullOrEmpty(ap.Subject))
                //        tagContents.AppendFormat("Subject: {0}\n", ap.Subject);
                //    if (!String.IsNullOrEmpty(ap.Details))
                //        tagContents.AppendFormat("Details: {0}\n", ap.Details);
                //    if (!String.IsNullOrEmpty(ap.Organizer.Address))
                //        tagContents.AppendFormat("Organizer Address: {0}\n", ap.Organizer.Address);
                //    if (!String.IsNullOrEmpty(ap.Location))
                //        tagContents.AppendFormat("Location: {0}\n", ap.Location);
                //    tagContents.AppendFormat("Start time: {0}\n", ap.StartTime);
                //    tagContents.AppendFormat("Duration: {0}\n", ap.Duration);
                //    tagContents.AppendFormat("AllDay? {0}\n", ap.AllDay ? "yes" : "no");
                //    if (ap.Reminder != null)
                //        tagContents.AppendFormat("Reminder: {0}\n", ap.Reminder);
                //}
                else if (specializedType == typeof(NdefLaunchAppRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract LaunchApp record info
                    var launchAppRecord = new NdefLaunchAppRecord(record);
                    tagContents.Append("-> LaunchApp record" + Environment.NewLine);
                    if (!string.IsNullOrEmpty(launchAppRecord.Arguments))
                        tagContents.AppendFormat("Arguments: {0}\n", launchAppRecord.Arguments);
                    if (launchAppRecord.PlatformIds != null)
                    {
                        foreach (var platformIdTuple in launchAppRecord.PlatformIds)
                        {
                            if (platformIdTuple.Key != null)
                                tagContents.AppendFormat("Platform: {0}\n", platformIdTuple.Key);
                            if (platformIdTuple.Value != null)
                                tagContents.AppendFormat("App ID: {0}\n", platformIdTuple.Value);
                        }
                    }
                }
                //else if (specializedType == typeof(NdefMimeImageRecordBase))
                //{
                //    // --------------------------------------------------------------------------
                //    // Convert and extract Image record info
                //    var imgRecord = new NdefMimeImageRecord(record);
                //    tagContents.Append("-> MIME / Image record" + Environment.NewLine);
                //    _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => SetStatusImage(await imgRecord.GetImageAsBitmap()));

                //}
                else
                {
                    // Other type, not handled by this demo
                    tagContents.Append("NDEF record not parsed by this demo app" + Environment.NewLine);
                }
            }
        }
Ejemplo n.º 9
0
        private ObservableCollection<string> readNDEFMEssage(NdefMessage message)
        {

            ObservableCollection<string> collection = new ObservableCollection<string>();
            foreach (NdefRecord record in message)
            {
                // Go through each record, check if it's a Smart Poster
                if (record.CheckSpecializedType(false) == typeof(NdefSpRecord))
                {
                    // Convert and extract Smart Poster info
                    var spRecord = new NdefSpRecord(record);
                    collection.Add("URI: " + spRecord.Uri);
                    collection.Add("Titles: " + spRecord.TitleCount());
                    collection.Add("1. Title: " + spRecord.Titles[0].Text);
                    collection.Add("Action set: " + spRecord.ActionInUse());
                }

                if (record.CheckSpecializedType(false) == typeof(NdefUriRecord))
                {
                    // Convert and extract Smart Poster info
                    var spRecord = new NdefUriRecord(record);
                    collection.Add("Text: " + spRecord.Uri);
                }
            }
            return collection;
        }
Ejemplo n.º 10
0
 void HandleClicked(object sender, EventArgs e)
 {
     var spRecord = new NdefSpRecord
     {
         Uri = "www.poz1.com",
         NfcAction = NdefSpActRecord.NfcActionType.DoAction,
     };
     spRecord.AddTitle(new NdefTextRecord
     {
         Text = "NFCForms - XamarinForms - Poz1.com",
         LanguageCode = "en"
     });
     // Add record to NDEF message
     var msg = new NdefMessage { spRecord };
     try
     {
         device.WriteTag(msg);
     }
     catch (Exception excp)
     {
         DisplayAlert("Error", excp.Message, "OK");
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed an Sms record.
 /// Checks the type and type name format and if the URI starts with the correct scheme.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be an Sms record, false if it's a different record.</returns>
 public new static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null) return false;
     if (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Payload != null)
     {
         if (record.Type.SequenceEqual(NdefUriRecord.UriType))
         {
             var testRecord = new NdefUriRecord(record);
             return testRecord.Uri.StartsWith(SmsScheme, StringComparison.OrdinalIgnoreCase);
         }
         if (record.Type.SequenceEqual(SmartPosterType))
         {
             var testRecord = new NdefSpRecord(record);
             return testRecord.Uri.StartsWith(SmsScheme, StringComparison.OrdinalIgnoreCase);
         }
     }
     return false;
 }
Ejemplo n.º 12
0
        private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
        {
            // Get the raw NDEF message data as byte array
            var rawMsg = message.Data.ToArray();
            // Let the NDEF library parse the NDEF message out of the raw byte array
            var ndefMessage = NdefMessage.FromByteArray(rawMsg);

            // Analysis result
            var tagContents = new StringBuilder();
           
            // Loop over all records contained in the NDEF message
            foreach (NdefRecord record in ndefMessage)
            {
                // --------------------------------------------------------------------------
                // Print generic information about the record
                if (record.Id != null && record.Id.Length > 0)
                {
                    // Record ID (if present)
                    tagContents.AppendFormat("Id: {0}\n", Encoding.UTF8.GetString(record.Id, 0, record.Id.Length));
                }
                // Record type name, as human readable string
                tagContents.AppendFormat("Type name: {0}\n", ConvertTypeNameFormatToString(record.TypeNameFormat));
                // Record type
                if (record.Type != null && record.Type.Length > 0)
                {
                    tagContents.AppendFormat("Record type: {0}\n",
                                             Encoding.UTF8.GetString(record.Type, 0, record.Type.Length));
                }

                // --------------------------------------------------------------------------
                // Check the type of each record
                // Using 'true' as parameter for CheckSpecializedType() also checks for sub-types of records,
                // e.g., it will return the SMS record type if a URI record starts with "sms:"
                // If using 'false', a URI record will always be returned as Uri record and its contents won't be further analyzed
                // Currently recognized sub-types are: SMS, Mailto, Tel, Nokia Accessories, NearSpeak, WpSettings
                var specializedType = record.CheckSpecializedType(true);

                if (specializedType == typeof(NdefMailtoRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract Mailto record info
                    var mailtoRecord = new NdefMailtoRecord(record);
                    tagContents.Append("-> Mailto record\n");
                    tagContents.AppendFormat("Address: {0}\n", mailtoRecord.Address);
                    tagContents.AppendFormat("Subject: {0}\n", mailtoRecord.Subject);
                    tagContents.AppendFormat("Body: {0}\n", mailtoRecord.Body);
                }
                else if (specializedType == typeof(NdefUriRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract URI record info
                    var uriRecord = new NdefUriRecord(record);
                    tagContents.Append("-> URI record\n");
                    tagContents.AppendFormat("URI: {0}\n", uriRecord.Uri);
                }
                else if (specializedType == typeof(NdefSpRecord))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract Smart Poster info
                    var spRecord = new NdefSpRecord(record);
                    tagContents.Append("-> Smart Poster record\n");
                    tagContents.AppendFormat("URI: {0}", spRecord.Uri);
                    tagContents.AppendFormat("Titles: {0}", spRecord.TitleCount());
                    if (spRecord.TitleCount() > 1)
                        tagContents.AppendFormat("1. Title: {0}", spRecord.Titles[0].Text);
                    tagContents.AppendFormat("Action set: {0}", spRecord.ActionInUse());
                    // You can also check the action (if in use by the record), 
                    // mime type and size of the linked content.
                }
                else if (specializedType == typeof (NdefLaunchAppRecord))
                {
                    
                    // --------------------------------------------------------------------------
                    // Convert and extract LaunchApp record info
                    var launchAppRecord = new NdefLaunchAppRecord(record);
                    tagContents.Append("-> LaunchApp record" + Environment.NewLine);
                   
                    if (!string.IsNullOrEmpty(launchAppRecord.Arguments))
                     
                        tagContents.AppendFormat("Arguments: {0}\n", launchAppRecord.Arguments);
                    if (launchAppRecord.PlatformIds != null)
                    {
                        foreach (var platformIdTuple in launchAppRecord.PlatformIds)
                        {
                            if (platformIdTuple.Key != null)
                                tagContents.AppendFormat("Platform: {0}\n", platformIdTuple.Key);
                            if (platformIdTuple.Value != null)
                                tagContents.AppendFormat("App ID: {0}\n", platformIdTuple.Value);
                        }
                    }
                }
                else
                {
                    // Other type, not handled by this demo
                    tagContents.Append("NDEF record not parsed by this demo app" + Environment.NewLine);
                }
            }
            // Update status text for UI
            SetStatusOutput(string.Format(AppResources.StatusTagParsed, tagContents));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Checks the type name format and type of this record and returns
 /// the appropriate specialized class, if one is available and known
 /// for this record type.
 /// </summary>
 /// <returns>Type name of the specialized class that can understand
 /// and manipulate the payload through convenience methods.</returns>
 public Type CheckSpecializedType(bool checkForSubtypes)
 {
     // Note: can't check for specialized types like the geo record
     // or the SMS record yet, as these are just convenience classes
     // for creating URI / Smart Poster records.
     if (checkForSubtypes)
     {
         // Need to check specialized URI / Sp records before checking for base types.
         if (NdefSmsRecord.IsRecordType(this))
         {
             return(typeof(NdefSmsRecord));
         }
         if (NdefMailtoRecord.IsRecordType(this))
         {
             return(typeof(NdefMailtoRecord));
         }
         if (NdefTelRecord.IsRecordType(this))
         {
             return(typeof(NdefTelRecord));
         }
         if (NdefNokiaAccessoriesRecord.IsRecordType(this))
         {
             return(typeof(NdefNokiaAccessoriesRecord));
         }
         if (NdefNearSpeakRecord.IsRecordType(this))
         {
             return(typeof(NdefNearSpeakRecord));
         }
         if (NdefWpSettingsRecord.IsRecordType(this))
         {
             return(typeof(NdefWpSettingsRecord));
         }
     }
     // Unique / base record types
     if (NdefUriRecord.IsRecordType(this))
     {
         return(typeof(NdefUriRecord));
     }
     if (NdefSpRecord.IsRecordType(this))
     {
         return(typeof(NdefSpRecord));
     }
     if (NdefTextRecord.IsRecordType(this))
     {
         return(typeof(NdefTextRecord));
     }
     if (NdefSpActRecord.IsRecordType(this))
     {
         return(typeof(NdefSpActRecord));
     }
     if (NdefSpSizeRecord.IsRecordType(this))
     {
         return(typeof(NdefSpSizeRecord));
     }
     if (NdefSpMimeTypeRecord.IsRecordType(this))
     {
         return(typeof(NdefSpMimeTypeRecord));
     }
     if (NdefLaunchAppRecord.IsRecordType(this))
     {
         return(typeof(NdefLaunchAppRecord));
     }
     if (NdefAndroidAppRecord.IsRecordType(this))
     {
         return(typeof(NdefAndroidAppRecord));
     }
     return(typeof(NdefRecord));
 }
Ejemplo n.º 14
0
 void HandleClicked(object sender, EventArgs e)
 {
     var spRecord = new NdefSpRecord
     {
         NfcAction = NdefSpActRecord.NfcActionType.DoAction,
     };
     spRecord.AddTitle(new NdefTextRecord
         {
             Text = "00001:5.49"
         });
     // Add record to NDEF message
     var msg = new NdefMessage { spRecord };
     try
     {
         device.WriteTag(msg);
     }
     catch (Exception excp)
     {
         DisplayAlert("Error", excp.Message, "OK");
     }
 }
Ejemplo n.º 15
0
        private NdefRecord GetPublishingMessage(Type type, string data)
        {
            NdefRecord retValue = null;

            if (type == typeof(NdefTextRecord))
            {
                var oRecord = new NdefTextRecord();
                oRecord.Text = data;
                retValue = oRecord;
            }
            else if (type == typeof(NdefSpRecord))
            {
                var oRecord = new NdefSpRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Uri:" + oRecord.Uri + ")");
            }
            else if (type == typeof(NdefUriRecord))
            {
                var oRecord = new NdefUriRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Uri:" + oRecord.Uri + ")");
            }
            else if (type == typeof(NdefTelRecord))
            {
                var oRecord = new NdefTelRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Tel:" + oRecord.TelNumber + ")");
            }
            else if (type == typeof(NdefMailtoRecord))
            {
                var oRecord = new NdefMailtoRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Subject:" + oRecord.Subject + ")");
            }
            else if (type == typeof(NdefAndroidAppRecord))
            {
                var oRecord = new NdefAndroidAppRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Package:" + oRecord.PackageName + ")");
            }
            else if (type == typeof(NdefLaunchAppRecord))
            {
                var oRecord = new NdefLaunchAppRecord();         
     
                string praid = CoreApplication.Id; // The Application Id value from your package.appxmanifest.
                string appName = Package.Current.Id.FamilyName + "!" + praid;

                NdefLaunchAppRecord launch = new NdefLaunchAppRecord();
                launch.AddPlatformAppId("Windows", appName);
                launch.Arguments = data;
                retValue = oRecord;
            }
            else if (type == typeof(NdefSmsRecord))
            {
                var oRecord = new NdefSmsRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Sms:" + oRecord.SmsBody + ")");
            }
            else if (type == typeof(NdefSmartUriRecord))
            {
                var oRecord = new NdefSmartUriRecord();
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Uri:" + oRecord.Uri + ")");
            }
            else
            {
                //
            }

            return retValue;
        }
Ejemplo n.º 16
0
        private string HandleNDEFRecord(NdefRecord record)
        {
            string tag = string.Empty;
            var specializedType = record.CheckSpecializedType(false);

            if (specializedType == typeof(NdefTextRecord))
            {
                var oRecord = new NdefTextRecord(record);
                try
                {
                    tag = oRecord.Text;
                    this.NotifyUser(tag, NotifyType.PublishMessage);
                }
                catch { }
            }
            else if (specializedType == typeof(NdefSpRecord))
            {
                var oRecord = new NdefSpRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Uri:" + oRecord.Uri + ")");
            }
            else if (specializedType == typeof(NdefUriRecord))
            {
                var oRecord = new NdefUriRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Uri:" + oRecord.Uri + ")");
            }
            else if (specializedType == typeof(NdefTelRecord))
            {
                var oRecord = new NdefTelRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Tel:" + oRecord.TelNumber + ")");
            }
            else if (specializedType == typeof(NdefMailtoRecord))
            {
                var oRecord = new NdefMailtoRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Subject:" + oRecord.Subject + ")");
            }
            else if (specializedType == typeof(NdefAndroidAppRecord))
            {
                var oRecord = new NdefAndroidAppRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Package:" + oRecord.PackageName + ")");
            }
            else if (specializedType == typeof(NdefLaunchAppRecord))
            {
                var oRecord = new NdefLaunchAppRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Platform:" + oRecord.PlatformIds + ")");
            }
            else if (specializedType == typeof(NdefSmsRecord))
            {
                var oRecord = new NdefSmsRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Sms:" + oRecord.SmsBody + ")");
            }
            else if (specializedType == typeof(NdefSmartUriRecord))
            {
                var oRecord = new NdefSmartUriRecord(record);
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supportint Type, Value (Uri:" + oRecord.Uri + ")");
            }
            else
            {
                //this.NotifyUser(NotifyType.PeerMessage, "Not Supporting Type");
            }

            return tag;
        }