|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object NDEFMessage
public class NDEFMessage
This class represents an NDEF message. An NDEF message consists of one or more NDEF records. This class allows the manipulation of the NDEF records inside the NDEF message in the memory. It provides methods to add, remove and update NDEF records in the message. The NFC Forum NDEF specification is used as basis for this class, but some features, for example, chunking defined in the NDEF specification are left to the API implementation. The NDEF message sent to the target must contain at least one NDEF record.
Constructor Summary | |
---|---|
NDEFMessage()
Creates an NDEF message that has no NDEF records. |
|
NDEFMessage(byte[] data,
int offset)
Creates an NDEF message from the byte array starting from the specified offset in the byte array. |
|
NDEFMessage(NDEFRecord[] records)
Creates an NDEF message containing the specified NDEF records. |
Method Summary | |
---|---|
void |
appendRecord(NDEFRecord record)
Adds a new NDEF record after the last NDEF record in the NDEF message. |
int |
getNumberOfRecords()
Returns the number of NDEFRecord objects in the NDEF message. |
NDEFRecord |
getRecord(byte[] id)
Returns the NDEF record with the specified payload identifier. |
NDEFRecord |
getRecord(int index)
Returns the NDEF record from the specified index in the NDEF message. |
NDEFRecord[] |
getRecord(NDEFRecordType recordType)
Returns the NDEF records with specified record type. |
NDEFRecord[] |
getRecords()
Returns all NDEF records in the NDEF message. |
NDEFRecordType[] |
getRecordTypes()
Returns the record type objects of all NDEF records in the NDEF message. |
void |
insertRecord(int index,
NDEFRecord record)
Adds the specified NDEF record to the NDEF records at the specified index. |
void |
removeRecord(int index)
Removes an NDEF record from the specified index. |
void |
setRecord(int index,
NDEFRecord record)
Replaces the NDEF record at the specified index. |
byte[] |
toByteArray()
Returns the whole NDEF message with all the NDEF records as a byte array. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NDEFMessage()
public NDEFMessage(byte[] data, int offset)
offset
must be a value greater
than or equal to 0 and less than the length of the byte array.
data
- the byte array containing the NDEF recordsoffset
- start index of the NFC Forum formatted data in the byte array
java.lang.NullPointerException
- if data
is null
java.lang.ArrayIndexOutOfBoundsException
- if offset
is invalid
java.lang.IllegalArgumentException
- if data
can not be formed to
NDEF messagepublic NDEFMessage(NDEFRecord[] records)
records
- NDEF records to be added to the NDEF message
java.lang.NullPointerException
- if records
is null
or if any of the given record objects inside the
records
array is null
java.lang.IllegalArgumentException
- if records
is an empty
array or payload identifiers in the NDEF records
are not uniqueMethod Detail |
---|
public void appendRecord(NDEFRecord record)
record
- the new NDEF record to be added
java.lang.NullPointerException
- if record
is null
java.lang.IllegalArgumentException
- if an NDEF record with the same
payload identifier already existspublic int getNumberOfRecords()
NDEFRecord
objects in the NDEF message.
public NDEFRecord getRecord(byte[] id)
id
- payload identifier of the requested NDEF record
null
if
matching record is not found
java.lang.NullPointerException
- if id
is null
public NDEFRecord getRecord(int index)
index
- index of the requested NDEF record
java.lang.IndexOutOfBoundsException
- if index
is invalidpublic NDEFRecord[] getRecord(NDEFRecordType recordType)
recordType
- type of the requested NDEF record
null
if no record
with the requested record type are found
java.lang.NullPointerException
- if recordType is null
public NDEFRecord[] getRecords()
public NDEFRecordType[] getRecordTypes()
public void insertRecord(int index, NDEFRecord record)
index
- index to which the new NDEF record is addedrecord
- new NDEF record to be added
java.lang.IndexOutOfBoundsException
- if index
is invalid
java.lang.NullPointerException
- if record
is null
java.lang.IllegalArgumentException
- if a NDEF record with the same
payload identifier already existspublic void removeRecord(int index)
index
- index of the NDEF record to be removed
java.lang.IndexOutOfBoundsException
- if index
is invalidpublic void setRecord(int index, NDEFRecord record)
index
- index of the record to be updatedrecord
- updated NDEF record
java.lang.IndexOutOfBoundsException
- if index
is invalid
java.lang.NullPointerException
- if record
is null
java.lang.IllegalArgumentException
- if an NDEF record with the
same payload identifier already exists, except the one that is
about to be replacedpublic byte[] toByteArray()
null
if
NDEFMessage
does not contain any NDEF records
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |