IT. Expert System.

Android Reference

NdefMessage


android.nfc

Class NdefMessage

  • All Implemented Interfaces:
    Parcelable


    public final class NdefMessage
    extends Object
    implements Parcelable
    Represents an immutable NDEF Message.

    NDEF (NFC Data Exchange Format) is a light-weight binary format, used to encapsulate typed data. It is specified by the NFC Forum, for transmission and storage with NFC, however it is transport agnostic.

    NDEF defines messages and records. An NDEF Record contains typed data, such as MIME-type media, a URI, or a custom application payload. An NDEF Message is a container for one or more NDEF Records.

    When an Android device receives an NDEF Message (for example by reading an NFC tag) it processes it through a dispatch mechanism to determine an activity to launch. The type of the first record in the message has special importance for message dispatch, so design this record carefully.

    Use NdefMessage(byte[]) to construct an NDEF Message from binary data, or NdefMessage(NdefRecord[]) to construct from one or more NdefRecords.

    NdefMessage and NdefRecord implementations are always available, even on Android devices that do not have NFC hardware.

    NdefRecords are intended to be immutable (and thread-safe), however they may contain mutable fields. So take care not to modify mutable fields passed into constructors, or modify mutable fields obtained by getter methods, unless such modification is explicitly marked as safe.

    See Also:
    NfcAdapter.ACTION_NDEF_DISCOVERED, NdefRecord
    • Constructor Detail

      • NdefMessage

        public NdefMessage(byte[] data)
                    throws FormatException
        Construct an NDEF Message by parsing raw bytes.

        Strict validation of the NDEF binary structure is performed: there must be at least one record, every record flag must be correct, and the total length of the message must match the length of the input data.

        This parser can handle chunked records, and converts them into logical NdefRecords within the message.

        Once the input data has been parsed to one or more logical records, basic validation of the tnf, type, id, and payload fields of each record is performed, as per the documentation on on NdefRecord.NdefRecord(short, byte[], byte[], byte[])

        If either strict validation of the binary format fails, or basic validation during record construction fails, a FormatException is thrown

        Deep inspection of the type, id and payload fields of each record is not performed, so it is possible to parse input that has a valid binary format and confirms to the basic validation requirements of NdefRecord.NdefRecord(short, byte[], byte[], byte[]), but fails more strict requirements as specified by the NFC Forum.

        It is safe to re-use the data byte array after construction: this constructor will make an internal copy of all necessary fields.

        Parameters:
        data - raw bytes to parse
        Throws:
        FormatException - if the data cannot be parsed
      • NdefMessage

        public NdefMessage(NdefRecord record,
                   NdefRecord... records)
        Construct an NDEF Message from one or more NDEF Records.
        Parameters:
        record - first record (mandatory)
        records - additional records (optional)
      • NdefMessage

        public NdefMessage(NdefRecord[] records)
        Construct an NDEF Message from one or more NDEF Records.
        Parameters:
        records - one or more records
    • Method Detail

      • getRecords

        public NdefRecord[] getRecords()
        Get the NDEF Records inside this NDEF Message.

        An NdefMessage always has one or more NDEF Records: so the following code to retrieve the first record is always safe (no need to check for null or array length >= 1):

         NdefRecord firstRecord = ndefMessage.getRecords()[0];
         
        Returns:
        array of one or more NDEF records.
      • getByteArrayLength

        public int getByteArrayLength()
        Return the length of this NDEF Message if it is written to a byte array with toByteArray().

        An NDEF Message can be formatted to bytes in different ways depending on chunking, SR, and ID flags, so the length returned by this method may not be equal to the length of the original byte array used to construct this NDEF Message. However it will always be equal to the length of the byte array produced by toByteArray().

        Returns:
        length of this NDEF Message when written to bytes with toByteArray()
        See Also:
        toByteArray()
      • toByteArray

        public byte[] toByteArray()
        Return this NDEF Message as raw bytes.

        The NDEF Message is formatted as per the NDEF 1.0 specification, and the byte array is suitable for network transmission or storage in an NFC Forum NDEF compatible tag.

        This method will not chunk any records, and will always use the short record (SR) format and omit the identifier field when possible.

        Returns:
        NDEF Message in binary format
        See Also:
        getByteArrayLength
      • describeContents

        public int describeContents()
        Description copied from interface: Parcelable
        Describe the kinds of special objects contained in this Parcelable's marshalled representation.
        Specified by:
        describeContents in interface Parcelable
        Returns:
        a bitmask indicating the set of special object types marshalled by the Parcelable.
      • hashCode

        public int hashCode()
        Description copied from class: Object
        Returns an integer hash code for this object. By contract, any two objects for which Object.equals(java.lang.Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

        Note that hash values must not change over time unless information used in equals comparisons also changes.

        See Writing a correct hashCode method if you intend implementing your own hashCode method.

        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • equals

        public boolean equals(Object obj)
        Returns true if the specified NDEF Message contains identical NDEF Records.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare this instance with.
        Returns:
        true if the specified object is equal to this Object; false otherwise.
        See Also:
        Object.hashCode()
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 10469 / 248537453. Delta: 0.05519 с