diff options
author | Nick Pelly <npelly@google.com> | 2012-01-24 13:22:58 -0800 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2012-01-26 14:21:19 -0800 |
commit | 1f5badc1cb08f10ddf4b09aaaf34060a23999a51 (patch) | |
tree | 1ed4d116df4898dd11e85cd48b0d83a099cb006b /core/java/android/nfc/NdefMessage.java | |
parent | 7e4ef61732d7de33e34f5935cfad51049f65116a (diff) | |
download | frameworks_base-1f5badc1cb08f10ddf4b09aaaf34060a23999a51.zip frameworks_base-1f5badc1cb08f10ddf4b09aaaf34060a23999a51.tar.gz frameworks_base-1f5badc1cb08f10ddf4b09aaaf34060a23999a51.tar.bz2 |
Add NdefMessage.getByteLength(), and more minor fixes:
Remove NdefMessage from dispatch(). It's already in the Tag.
/*package*/ cleanup
Fix sitemap after removal of NFCDemo
Change-Id: Ie1f6d9ea98144aa97f56bb709a33f5d0ef916e8b
Diffstat (limited to 'core/java/android/nfc/NdefMessage.java')
-rw-r--r-- | core/java/android/nfc/NdefMessage.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/core/java/android/nfc/NdefMessage.java b/core/java/android/nfc/NdefMessage.java index c83144f..dc501ab 100644 --- a/core/java/android/nfc/NdefMessage.java +++ b/core/java/android/nfc/NdefMessage.java @@ -158,7 +158,28 @@ public final class NdefMessage implements Parcelable { } /** - * Return this NDEF MEssage as raw bytes.<p> + * 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 Message as raw bytes.<p> * 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.<p> @@ -166,13 +187,10 @@ public final class NdefMessage implements Parcelable { * short record (SR) format and omit the identifier field when possible. * * @return NDEF Message in binary format + * @see getByteArrayLength */ public byte[] toByteArray() { - int length = 0; - for (NdefRecord r : mRecords) { - length += r.getByteLength(); - } - + int length = getByteArrayLength(); ByteBuffer buffer = ByteBuffer.allocate(length); for (int i=0; i<mRecords.length; i++) { |