コード例 #1
0
ファイル: NdefRecord.cs プロジェクト: xxzztt/ndef-nfc
 /// <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));
 }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: Doluci/ndef-nfc
        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);
                }
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: Doluci/ndef-nfc
        // ----------------------------------------------------------------------------------------------------

        private void BtnWriteLaunchApp_Click(object sender, RoutedEventArgs e)
        {
            // Create a new LaunchApp record to launch this app
            // The app will print the arguments when it is launched (see MainPage.OnNavigatedTo() method)
            var record = new NdefLaunchAppRecord { Arguments = "Hello World" };
            // WindowsPhone is the pre-defined platform ID for WP8.
            // You can get the application ID from the WMAppManifest.xml file
            record.AddPlatformAppId("WindowsPhone", "{544ec154-b521-4d73-9405-963830adb213}");
            // The app platform for a Windows 8 computer is Windows. 
            // The format of the proximity app Id is <package family name>!<app Id>. 
            // You can get the package family name from the Windows.ApplicationModel.Package.Current.Id.FamilyName property. 
            // You must copy the app Id value from the Id attribute of the Application element in the 
            // package manifest for your app.
            record.AddPlatformAppId("Windows", Windows.ApplicationModel.Package.Current.Id.FamilyName + "!" + "NdefDemoWin");

            // Publish the record using the proximity device
            PublishRecord(record, true);
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: RyanAClark/Easy-NFC
        private void map_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            //Sup = 1;
            var record = new NdefLaunchAppRecord { Arguments = "map1234" };
            // WindowsPhone is the pre-defined platform ID for WP8.
            // You can get the application ID from the WMAppManifest.xml file
            record.AddPlatformAppId("WindowsPhone", "{544ec154-b521-4d73-9405-963830adb213}");
            // Publish the record using the proximity device
            recordresult = record.Arguments;
            PublishRecord(record, true);




        }
コード例 #5
0
ファイル: MainPage.xaml.cs プロジェクト: RyanAClark/Easy-NFC
        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));
        }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: RyanAClark/Easy-NFC
 private void BtnWriteLaunchApp_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     Sup = 0;
     // Create a new LaunchApp record to launch this app
     // The app will print the arguments when it is launched (see MainPage.OnNavigatedTo() method)
     var record = new NdefLaunchAppRecord { Arguments = write_to_tag_box.Text};
     // WindowsPhone is the pre-defined platform ID for WP8.
     // You can get the application ID from the WMAppManifest.xml file
     record.AddPlatformAppId("WindowsPhone", "{544ec154-b521-4d73-9405-963830adb213}");
     // Publish the record using the proximity device
     recordresult = record.Arguments;
     PublishRecord(record, true);
     Sup = 1;
    
 }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: RyanAClark/Easy-NFC
        private async void ListenBtn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Sup = 0;
            if(check==false){
                check = true;
                SetStatusOutput(string.Format("RECORDING"));
            // Start speech recognition and wait for the async process to finish
            var recoResult = await _recognizer.RecognizeAsync();
            // Inform the user about the result and the next steps
            SetStatusOutput(string.Format("You said \"{0}\"\nPlease touch a tag to write the message.", recoResult.Text));
            // Create a LaunchApp record, specifying our recognized text as arguments
         
           var record = new NdefLaunchAppRecord { Arguments = recoResult.Text };
            // Add the app ID of your app!
          record.AddPlatformAppId("WindowsPhone", "{544ec154-b521-4d73-9405-963830adb213}");
            // Wrap the record into a message, which can be written to a tag       

            recordresult = recoResult.Text;
            PublishRecord(record, true);
            check = false;
            Sup = 1;
            }
           
        }
コード例 #8
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));
 }
コード例 #9
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;
        }
コード例 #10
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;
        }
コード例 #11
0
ファイル: MainPage.xaml.cs プロジェクト: Doluci/ndef-nfc
        private async 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 (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(NdefVcardRecordBase))
                {
                    // --------------------------------------------------------------------------
                    // Convert and extract business card info
                    var vcardRecord = await NdefVcardRecord.CreateFromGenericBaseRecord(record);
                    tagContents.Append("-> Business Card record" + Environment.NewLine);
                    tagContents.AppendFormat("vCard Version: {0}" + Environment.NewLine,
                                             vcardRecord.VCardFormatToWrite == VCardFormat.Version2_1 ? "2.1" : "3.0");
                    var contact = vcardRecord.ContactData;
                    var contactInfo = await contact.GetPropertiesAsync();
                    foreach (var curProperty in contactInfo.OrderBy(i => i.Key))
                    {
                        tagContents.Append(String.Format("{0}: {1}" + Environment.NewLine, curProperty.Key, curProperty.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));
        }
コード例 #12
0
ファイル: MainPage.xaml.cs プロジェクト: SpivEgin/ndef-nfc
        // ----------------------------------------------------------------------------------------------------

        private void BtnWriteLaunchApp_Click(object sender, RoutedEventArgs e)
        {
            // Create a new LaunchApp record to launch this app
            // The app will print the arguments when it is launched (see MainPage.OnNavigatedTo() method)
            var record = new NdefLaunchAppRecord { Arguments = "Hello World" };

            // WindowsPhone is the pre-defined platform ID for WP8.
            // You can get the application ID from the WMAppManifest.xml file
            //record.AddPlatformAppId("WindowsPhone", "{544ec154-b521-4d73-9405-963830adb213}");

            // The app platform for a Windows 8 computer is Windows. 
            // The format of the proximity app Id is <package family name>!<app Id>. 
            // You can get the package family name from the Windows.ApplicationModel.Package.Current.Id.FamilyName property. 
            // You must copy the app Id value from the Id attribute of the Application element in the 
            // package manifest for your app.

            var familyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;
            //var appId = Windows.ApplicationModel.Store.CurrentApp.AppId;    // Crashes when app is not installed from the app store!
            var appId = "8bf48432-f9c8-48cd-a014-c44d868347dc";
            // Issue on Windows 10: http://stackoverflow.com/questions/34221812/how-to-launch-my-app-via-nfc-tag
            // Issue on Windows 10: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/c9653f06-0d48-498f-9b3e-335435780fd4/cw81windows-81-app-license-error-0x803f6107?forum=wpdevelop
            record.AddPlatformAppId("Windows", "{" + familyName + "!" + appId + "}");
            record.AddPlatformAppId("WindowsPhone", appId);

            // Publish the record using the proximity device
            PublishRecord(record, true);
        }