diff options
author | Nick Pelly <npelly@google.com> | 2012-01-05 15:13:01 +1100 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2012-01-25 13:17:19 -0800 |
commit | c97a552023c3c71079b39092e80c9b44f25a789b (patch) | |
tree | 639e700cdd538f2ebd080143182fa30bb32fdd2a /core/java/android/nfc/NdefMessage.java | |
parent | dc828acd5fadb266b13cce459b1cacfad8ef7aef (diff) | |
download | frameworks_base-c97a552023c3c71079b39092e80c9b44f25a789b.zip frameworks_base-c97a552023c3c71079b39092e80c9b44f25a789b.tar.gz frameworks_base-c97a552023c3c71079b39092e80c9b44f25a789b.tar.bz2 |
Improve NDEF API's
o Add NdefRecord.toMimeType()
Maps the record to a MIME type
o Add NdefRecord.toUri()
Maps the record to a URI
o Add hidden NfcAdapter.dispatch()
Helps test the dispatch path.
o Modify createMime(), createUri() and createExternal():
Do not try and strictly follow RFC requirements for URI or MIME content
types. This just leads to heartbreak - the RFC requirements are too strict.
For example RFC1341 forbids the use of '.' in a MIME type, however this is in
common use in types such as "application/vnd.companyname". I think the best
approach is to only remove 'obvious' whitespace issues, and to convert
uppercase to lowercase as per Android guidelines.
Change-Id: Id686f5f3b05b2dceafad48e1cfcbdb2b3890b854
Diffstat (limited to 'core/java/android/nfc/NdefMessage.java')
-rw-r--r-- | core/java/android/nfc/NdefMessage.java | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/core/java/android/nfc/NdefMessage.java b/core/java/android/nfc/NdefMessage.java index 38bc16d..c83144f 100644 --- a/core/java/android/nfc/NdefMessage.java +++ b/core/java/android/nfc/NdefMessage.java @@ -92,9 +92,7 @@ public final class NdefMessage implements Parcelable { * @throws FormatException if the data cannot be parsed */ public NdefMessage(byte[] data) throws FormatException { - if (data == null) { - throw new NullPointerException("null data"); - } + if (data == null) throw new NullPointerException("data is null"); ByteBuffer buffer = ByteBuffer.wrap(data); mRecords = NdefRecord.parse(buffer, false); @@ -112,9 +110,8 @@ public final class NdefMessage implements Parcelable { */ public NdefMessage(NdefRecord record, NdefRecord ... records) { // validate - if (record == null) { - throw new NullPointerException("record cannot be null"); - } + if (record == null) throw new NullPointerException("record cannot be null"); + for (NdefRecord r : records) { if (r == null) { throw new NullPointerException("record cannot be null"); @@ -147,7 +144,12 @@ public final class NdefMessage implements Parcelable { /** * Get the NDEF Records inside this NDEF Message.<p> - * An NDEF Message always has one or more NDEF Records. + * An {@link 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): + * <pre> + * NdefRecord firstRecord = ndefMessage.getRecords()[0]; + * </pre> * * @return array of one or more NDEF records. */ |