Exemplo n.º 1
0
        /// <summary>
        /// Returns the string formatted payload
        /// </summary>
        /// <param name="type">type of <see cref="NFCNdefTypeFormat"/></param>
        /// <param name="payload">record payload</param>
        /// <param name="uri">record uri</param>
        /// <returns>String formatted payload</returns>
        internal static string GetMessage(NFCNdefTypeFormat type, byte[] payload, string uri)
        {
            string message;

            if (!string.IsNullOrWhiteSpace(uri))
            {
                message = uri;
            }
            else
            {
                if (type == NFCNdefTypeFormat.WellKnown)
                {
                    // NDEF_WELLKNOWN Text record
                    var status             = payload[0];
                    var enc                = status & 0x80;
                    var languageCodeLength = status & 0x3F;
                    if (enc == 0)
                    {
                        message = Encoding.UTF8.GetString(payload, languageCodeLength + 1, payload.Length - languageCodeLength - 1);
                    }
                    else
                    {
                        message = Encoding.Unicode.GetString(payload, languageCodeLength + 1, payload.Length - languageCodeLength - 1);
                    }
                }
                else
                {
                    // Other NDEF types
                    message = Encoding.UTF8.GetString(payload, 0, payload.Length);
                }
            }
            return(message);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the string formatted payload
        /// </summary>
        /// <param name="type">type of <see cref="NFCNdefTypeFormat"/></param>
        /// <param name="payload">record payload</param>
        /// <param name="uri">record uri</param>
        /// <returns>String formatted payload</returns>
        internal static string GetMessage(NFCNdefTypeFormat type, byte[] payload, string uri)
        {
            var message = string.Empty;

            if (!string.IsNullOrWhiteSpace(uri))
            {
                message = uri;
            }
            else
            {
                if (type == NFCNdefTypeFormat.WellKnown)
                {
                    // NDEF_WELLKNOWN Text record
                    var languageCodeLength = payload[0] & 0x63;
                    message = Encoding.UTF8.GetString(payload, languageCodeLength + 1, payload.Length - languageCodeLength - 1);
                }
                else
                {
                    // Other NDEF types
                    message = Encoding.UTF8.GetString(payload, 0, payload.Length);
                }
            }

            return(message);
        }
Exemplo n.º 3
0
        async void Publish(NFCNdefTypeFormat?type = null)
        {
            try
            {
                if (ChkReadOnly.IsChecked)
                {
                    if (!await DisplayAlert("Warning", "Make a Tag read-only is permanent and can't be undone. Are you sure?", "Yes", "No"))
                    {
                        ChkReadOnly.IsChecked = false;
                        return;
                    }
                    _makeReadOnly = true;
                }
                else
                {
                    _makeReadOnly = false;
                }

                if (type.HasValue)
                {
                    _type = type.Value;
                }
                CrossNFC.Current.StartPublishing(!type.HasValue);
            }
            catch (System.Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }
Exemplo n.º 4
0
 async void Publish(NFCNdefTypeFormat?type = null)
 {
     try
     {
         if (type.HasValue)
         {
             _type = type.Value;
         }
         CrossNFC.Current.StartPublishing(!type.HasValue);
     }
     catch (System.Exception ex)
     {
         await ShowAlert(ex.Message);
     }
 }