다음을 통해 공유


NdefRecord Constructors

Definition

Overloads

NdefRecord(Byte[])
Obsolete.

Construct an NDEF Record from raw bytes.

NdefRecord(Int16, Byte[], Byte[], Byte[])

Construct an NDEF Record from its component fields.

NdefRecord(Byte[])

Caution

deprecated

Construct an NDEF Record from raw bytes.

[Android.Runtime.Register(".ctor", "([B)V", "")]
[System.Obsolete("deprecated")]
public NdefRecord (byte[]? data);
[<Android.Runtime.Register(".ctor", "([B)V", "")>]
[<System.Obsolete("deprecated")>]
new Android.Nfc.NdefRecord : byte[] -> Android.Nfc.NdefRecord

Parameters

data
Byte[]

raw bytes to parse

Attributes

Exceptions

if the data cannot be parsed into a valid record

Remarks

Construct an NDEF Record from raw bytes.

This method is deprecated, use NdefMessage#NdefMessage(byte[]) instead. This is because it does not make sense to parse a record: the NDEF binary format is only defined for a message, and the record flags MB and ME do not make sense outside of the context of an entire message.

This implementation will attempt to parse a single record by ignoring the MB and ME flags, and otherwise following the rules of NdefMessage#NdefMessage(byte[]).

This member is deprecated. use NdefMessage#NdefMessage(byte[]) instead.

Java documentation for android.nfc.NdefRecord.NdefRecord(byte[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

NdefRecord(Int16, Byte[], Byte[], Byte[])

Construct an NDEF Record from its component fields.

[Android.Runtime.Register(".ctor", "(S[B[B[B)V", "")]
public NdefRecord (short tnf, byte[]? type, byte[]? id, byte[]? payload);
[<Android.Runtime.Register(".ctor", "(S[B[B[B)V", "")>]
new Android.Nfc.NdefRecord : int16 * byte[] * byte[] * byte[] -> Android.Nfc.NdefRecord

Parameters

tnf
Int16

a 3-bit TNF constant

type
Byte[]

byte array, containing zero to 255 bytes, or null

id
Byte[]

byte array, containing zero to 255 bytes, or null

payload
Byte[]

byte array, containing zero to (2 ** 32 - 1) bytes, or null

Attributes

Remarks

Construct an NDEF Record from its component fields.

Recommend to use helpers such as {#createUri} or {#createExternal where possible, since they perform stricter validation that the record is correctly formatted as per NDEF specifications. However if you know what you are doing then this constructor offers the most flexibility.

An NdefRecord represents a logical (complete) record, and cannot represent NDEF Record chunks.

Basic validation of the tnf, type, id and payload is performed as per the following rules: <ul> <li>The tnf paramter must be a 3-bit value.</li> <li>Records with a tnf of #TNF_EMPTY cannot have a type, id or payload.</li> <li>Records with a tnf of #TNF_UNKNOWN or 0x07 cannot have a type.</li> <li>Records with a tnf of #TNF_UNCHANGED are not allowed since this class only represents complete (unchunked) records.</li> </ul> This minimal validation is specified by NFCForum-TS-NDEF_1.0 section 3.2.6 (Type Name Format).

If any of the above validation steps fail then IllegalArgumentException is thrown.

Deep inspection of the type, id and payload fields is not performed, so it is possible to create NDEF Records that conform to section 3.2.6 but fail other more strict NDEF specification requirements. For example, the payload may be invalid given the tnf and type.

To omit a type, id or payload field, set the parameter to an empty byte array or null.

Java documentation for android.nfc.NdefRecord.NdefRecord(short, byte[], byte[], byte[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to