示例#1
0
        /// <summary>
        /// Send an NDEF message to the remote device
        /// </summary>
        /// <param name="type">The type of NDEF Record</param>
        /// <param name="ID">The ID of NDEF Record</param>
        /// <param name="payload">The payload of NDEF Record</param>
        /// <param name="payloadLength">The length of payload</param>
        /// <returns>Returns true if initialize succeeded, false otherwise</returns>
        public bool SendNDEF(byte[] type, byte[] ID, byte[] payload, uint payloadLength)
        {
            NfcNdefRecord  NfcNdefRecord  = new NfcNdefRecord(NfcRecordTypeNameFormat.WellKnown, type, ID, payload, payloadLength);
            NfcNdefMessage NfcNdefMessage = new NfcNdefMessage();

            try
            {
                NfcNdefMessage.AppendRecord(NfcNdefRecord);
            }
            catch (Exception e)
            {
                LogImplementation.DLog("Failed append record " + e.Message);
                return(false);
            }

            try
            {
                nfcP2P.SendNdefMessageAsync(NfcNdefMessage);
                return(true);
            }
            catch (Exception e)
            {
                LogImplementation.DLog("Failed send message " + e.Message);
                return(false);
            }
        }
        /// <summary>
        /// Sends an NDEF message to the remote device.
        /// </summary>
        /// <param name="type">The type of NDEF Record</param>
        /// <param name="ID">The ID of NDEF Record</param>
        /// <param name="payload">The payload of NDEF Record</param>
        /// <param name="payloadLength">The length of payload</param>
        /// <returns>Returns true if initialize succeeded, false otherwise</returns>
        public bool SendNdef(byte[] type, byte[] ID, byte[] payload)
        {
            NfcNdefRecord  ndefRecord  = new NfcNdefRecord(NfcRecordTypeNameFormat.WellKnown, type, ID, payload, (uint)payload.Length);
            NfcNdefMessage ndefMessage = new NfcNdefMessage();

            try
            {
                ndefMessage.AppendRecord(ndefRecord);
            }
            catch (Exception e)
            {
                Tizen.Log.Debug("NFC_APP", "Failed append record " + e.Message);
                return(false);
            }

            try
            {
                p2pDevice.SendNdefMessageAsync(ndefMessage);
                return(true);
            }
            catch (Exception e)
            {
                Tizen.Log.Debug("NFC_APP", "Failed send message " + e.Message);
                return(false);
            }
        }