Ejemplo n.º 1
0
        public static TextParsedResult parse(Result result)
        {
            sbyte[] bytes = result.RawBytes;
            if (bytes == null)
            {
                return(null);
            }
            NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);

            if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
            {
                return(null);
            }
            if (!ndefRecord.Type.Equals(NDEFRecord.TEXT_WELL_KNOWN_TYPE))
            {
                return(null);
            }
            System.String[] languageText = decodeTextPayload(ndefRecord.Payload);
            return(new TextParsedResult(languageText[0], languageText[1]));
        }
Ejemplo n.º 2
0
        public static URIParsedResult parse(Result result)
        {
            sbyte[] bytes = result.RawBytes;
            if (bytes == null)
            {
                return(null);
            }
            NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);

            if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
            {
                return(null);
            }
            if (!ndefRecord.Type.Equals(NDEFRecord.URI_WELL_KNOWN_TYPE))
            {
                return(null);
            }
            System.String fullURI = decodeURIPayload(ndefRecord.Payload);
            return(new URIParsedResult(fullURI, null));
        }
        public static NDEFSmartPosterParsedResult parse(Result result)
        {
            sbyte[] bytes = result.RawBytes;
            if (bytes == null)
            {
                return(null);
            }
            NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0);

            // Yes, header record starts and ends a message
            if (headerRecord == null || !headerRecord.MessageBegin || !headerRecord.MessageEnd)
            {
                return(null);
            }
            if (!headerRecord.Type.Equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE))
            {
                return(null);
            }

            int        offset       = 0;
            int        recordNumber = 0;
            NDEFRecord ndefRecord   = null;

            sbyte[] payload = headerRecord.Payload;
            int     action  = NDEFSmartPosterParsedResult.ACTION_UNSPECIFIED;

            System.String title = null;
            System.String uri   = null;

            while (offset < payload.Length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null)
            {
                if (recordNumber == 0 && !ndefRecord.MessageBegin)
                {
                    return(null);
                }

                System.String type = ndefRecord.Type;
                if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.Equals(type))
                {
                    System.String[] languageText = NDEFTextResultParser.decodeTextPayload(ndefRecord.Payload);
                    title = languageText[1];
                }
                else if (NDEFRecord.URI_WELL_KNOWN_TYPE.Equals(type))
                {
                    uri = NDEFURIResultParser.decodeURIPayload(ndefRecord.Payload);
                }
                else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.Equals(type))
                {
                    action = ndefRecord.Payload[0];
                }
                recordNumber++;
                offset += ndefRecord.TotalRecordLength;
            }

            if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.MessageEnd))
            {
                return(null);
            }

            return(new NDEFSmartPosterParsedResult(action, uri, title));
        }