/// <summary> /// Deletes any details currently stored in the Smart Poster /// and re-initializes them by parsing the contents of the payload. /// </summary> private void ParsePayloadToData(byte[] payload) { InitializeData(); if (payload == null || payload.Length == 0) { return; } var message = NdefMessage.FromByteArray(payload); foreach (NdefRecord record in message) { var specializedType = record.CheckSpecializedType(false); if (specializedType == null) { continue; } if (specializedType == typeof(NdefUriRecord)) { // URI RecordUri = new NdefUriRecord(record); } else if (specializedType == typeof(NdefTextRecord)) { // Title var textRecord = new NdefTextRecord(record); if (Titles == null) { Titles = new List <NdefTextRecord>(); } Titles.Add(textRecord); } else if (specializedType == typeof(NdefSpActRecord)) { // Action _recordAction = new NdefSpActRecord(record); } else if (specializedType == typeof(NdefSpSizeRecord)) { // Size _recordSize = new NdefSpSizeRecord(record); } else if (specializedType == typeof(NdefSpMimeTypeRecord)) { // Mime Type _recordMimeType = new NdefSpMimeTypeRecord(record); } else if (specializedType == typeof(NdefMimeImageRecordBase)) { // Image _recordImage = new NdefMimeImageRecordBase(record); } else { Debug.WriteLine("Sp: Don't know how to handle this record: " + BitConverter.ToString(record.Type)); } } }
/// <summary> /// Add an (optional) title to the Smart Poster. /// </summary> /// <remarks> /// It is possible to add more than one title as each title text /// record can have a different language. The phone is then recommended /// to choose the text record with the language that makes most sense /// to the user. /// </remarks> /// <param name="newTitle">(additional) title to be stored in the Smart Poster.</param> public void AddTitle(NdefTextRecord newTitle) { if (Titles == null) { Titles = new List <NdefTextRecord>(); } Titles.Add(new NdefTextRecord(newTitle)); AssemblePayload(); }
private async void DoWriteTag() { WritingTag = true; Result = ""; NdefLibrary.Ndef.NdefMessage message = new NdefMessage(); NdefTextRecord record = new NdefTextRecord(); record.LanguageCode = "en"; record.TextEncoding = NdefTextRecord.TextEncodingType.Utf8; record.Text = Message; message.Add(record); var result = await _writeTask.WriteTag(message); if (result.DidSucceed) { Result = "Wrote Message to tag with ID " + result.NFCTag.Id; } else { switch(result.ReasonForFailure) { case FailureReasons.TagReadOnly: Result = "The tag was read only"; break; case FailureReasons.TagTooSmall: Result = "The tag was too small for this message"; break; case FailureReasons.ErrorDuringWrite: Result = "An error occured whislt trying to write the tag"; break; case FailureReasons.UnableToFormatTag: Result = "The tag was not formatted. Please format it first"; break; case FailureReasons.Unkown: Result = "An unkown error occured"; break; case FailureReasons.TagLostDuringWrite: Result = "The tag was removed whilst it was been written to"; break; default: throw new ArgumentOutOfRangeException(); } } WritingTag = false; }
static void r_NewNdefMessageDetected(NdefMessage message, int readerId) { Answer a = answers.Find(an => an.ReaderID == readerId); if (a == null) { a = new Answer(readerId); answers.Add(a); Console.WriteLine("Buzzer '{0}' initialisiert", a.Label); } var textRecord = new NdefTextRecord(message.First()); Console.WriteLine("Tag '{0}' an Buzzer '{1}'", textRecord.Text, a.Label); }
public MessageViewModel(NdefLibrary.Ndef.NdefRecord message) { Type type = message.CheckSpecializedType(true); Type = type.Name; Info = "Feel free to add this mapping to the message view model"; if (type == typeof (NdefLibrary.Ndef.NdefTextRecord)) { var text = new NdefTextRecord(message); Info = string.Format("The message on the tag is \"{0}\". The language is \"{1}\"", text.Text, text.LanguageCode); } if (type == typeof(NdefLibrary.Ndef.NdefUriRecord)) { var text = new NdefUriRecord(message); Info = string.Format("The URI on the tag is \"{0}\"", text.Uri); } }
public void ApplicationBarIconButton_Click(object sender, System.EventArgs e) { //if (_device == null) return; //// Make sure we're not already publishing another message //StopPublishingMessage(false); var str = TxtFloor.Text + "|" + TxtZone.Text + "|" + LatitudeTextBlock.Text + "|" + LongitudeTextBlock.Text; var record = new NdefTextRecord { Text = str, LanguageCode = "en-US" }; PublishRecord(record,true); // var msg = new NdefMessage {fRecord}; //_device.PublishBinaryMessage( // "NDEF:WriteTag", // msg.ToByteArray().AsBuffer(), // MessageWrittenHandler); // SetStatusOutput("Message written"); // StopPublishingMessage(true); }
/// <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)); }
/// <summary> /// Add an (optional) title to the Smart Poster. /// </summary> /// <remarks> /// It is possible to add more than one title as each title text /// record can have a different language. The phone is then recommended /// to choose the text record with the language that makes most sense /// to the user. /// </remarks> /// <param name="newTitle">(additional) title to be stored in the Smart Poster.</param> public void AddTitle(NdefTextRecord newTitle) { if (Titles == null) Titles = new List<NdefTextRecord>(); Titles.Add(new NdefTextRecord(newTitle)); AssemblePayload(); }
/// <summary> /// Deletes any details currently stored in the Smart Poster /// and re-initializes them by parsing the contents of the payload. /// </summary> private void ParsePayloadToData(byte[] payload) { InitializeData(); if (payload == null || payload.Length == 0) return; var message = NdefMessage.FromByteArray(payload); foreach (NdefRecord record in message) { var specializedType = record.CheckSpecializedType(false); if (specializedType == null) continue; if (specializedType == typeof(NdefUriRecord)) { // URI RecordUri = new NdefUriRecord(record); } else if (specializedType == typeof (NdefTextRecord)) { // Title var textRecord = new NdefTextRecord(record); if (Titles == null) Titles = new List<NdefTextRecord>(); Titles.Add(textRecord); } else if (specializedType == typeof (NdefSpActRecord)) { // Action _recordAction = new NdefSpActRecord(record); } else if (specializedType == typeof (NdefSpSizeRecord)) { // Size _recordSize = new NdefSpSizeRecord(record); } else if (specializedType == typeof (NdefSpMimeTypeRecord)) { // Mime Type _recordMimeType = new NdefSpMimeTypeRecord(record); } else if (specializedType == typeof(NdefMimeImageRecordBase)) { // Image _recordImage = new NdefMimeImageRecordBase(record); } else { Debug.WriteLine("Sp: Don't know how to handle this record: " + BitConverter.ToString(record.Type)); } } }
/// <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)); }
private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage 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) { if (NdefTextRecord.IsRecordType(record)) { // Convert and extract URI info var textRecord = new NdefTextRecord(record); string[] str = textRecord.Text.Split('|'); var Floor_st = str[0]; var Zone_st = str[1]; var latitude = str[2]; var longtitude = str[3]; Latitud_do = double.Parse(latitude); Longtitude_do = double.Parse(longtitude); SetLogStatus("Floor: " + Floor_st + " Zone: " + Zone_st); SetFloorStatus("Latitude: " + latitude + " Longitude: " + longtitude); store.AddDb(Floor_st, Zone_st, Latitud_do, Longtitude_do); } } <<<<<<< HEAD }
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; }
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; }