/** * Return the length of this NDEF Message if it is written to a byte array * with {@link #toByteArray}.<p> * 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 * {@link #toByteArray}. * * @return length of this NDEF Message when written to bytes with {@link #toByteArray} * @see #toByteArray */ public int getByteArrayLength() { int length = 0; for (NdefRecord r : mRecords) { length += r.getByteLength(); } return length; }
/** * Return this NDEF Record as a byte array.<p> * This method is deprecated, use {@link NdefMessage#toByteArray} * instead. This is because the NDEF binary format is not defined for * a record outside of the context of a message: the MB and ME flags * cannot be set without knowing the location inside a message.<p> * This implementation will attempt to serialize a single record by * always setting the MB and ME flags (in other words, assume this * is a single-record NDEF Message).<p> * * @deprecated use {@link NdefMessage#toByteArray()} instead */ @Deprecated public byte[] toByteArray() { ByteBuffer buffer = ByteBuffer.allocate(getByteLength()); writeToByteBuffer(buffer, true, true); return buffer.array(); }