1616
1717package android .nfc ;
1818
19+ import android .content .Context ;
1920import android .nfc .tech .IsoDep ;
2021import android .nfc .tech .MifareClassic ;
2122import android .nfc .tech .MifareUltralight ;
3334import java .util .Arrays ;
3435
3536/**
36- * Represents a (generic) discovered tag.
37+ * Represents an NFC tag that has been discovered .
3738 * <p>
38- * A tag is a passive NFC element, such as NFC Forum Tag's, MIFARE class Tags,
39- * Sony FeliCa Tags, etc.
39+ * {@link Tag} is an immutable object that represents the state of a NFC tag at
40+ * the time of discovery. It can be used as a handle to {@link TagTechnology} classes
41+ * to perform advanced operations, or directly queried for its ID ({@link #getId} and the
42+ * set of technologies it contains ({@link #getTechList}). Arrays passed to and
43+ * returned by this class are *not* cloned, so be careful not to modify them.
44+ * <p>
45+ * A new tag object is created every time a tag is discovered (comes into range), even
46+ * if it is the same physical tag. If a tag is removed and then returned into range, then
47+ * only the most recent tag object can be successfully used to create a {@link TagTechnology}.
48+ *
49+ * <h3>Tag Dispatch</h3>
50+ * When a tag is discovered, a {@link Tag} object is created and passed to a
51+ * single application via the {@link NfcAdapter#EXTRA_TAG} extra in a
52+ * {@link Context#startActivity} {@link android.content.Intent}. A four stage dispatch is used to select the
53+ * most appropriate application to handle the tag. The Android OS executes each stage in order,
54+ * and completes dispatch as soon as a single matching application is found. If there are multiple
55+ * matching applications found at any one stage then the Android Activity Chooser dialog is shown
56+ * to allow the user to select the application.
57+ * <h4>1. Foreground activity dispatch</h4>
58+ * A foreground activity that has called {@link NfcAdapter#enableForegroundDispatch} is
59+ * given priority. See the documentation on {#link NfcAdapter#enableForegroundDispatch} for
60+ * its usage.
61+ * <h4>2. NDEF data dispatch</h4>
62+ * If the tag contains NDEF data, then {@link Context#startActivity} is called with
63+ * {@link NfcAdapter#ACTION_NDEF_DISCOVERED} and a data URI determined from the
64+ * first NDEF Record in the first NDEF Message in the Tag. This allows NDEF tags to be given
65+ * priority dispatch to applications that can handle the content.
66+ * See {@link NfcAdapter#ACTION_NDEF_DISCOVERED} for more detail. If the tag does not contain
67+ * NDEF data, or if no application is registered
68+ * for {@link NfcAdapter#ACTION_NDEF_DISCOVERED} with a matching data URI then dispatch moves
69+ * to stage 3.
70+ * <h4>3. Tag Technology dispatch</h4>
71+ * {@link Context#startActivity} is called with {@link NfcAdapter#ACTION_TECH_DISCOVERED} to
72+ * dispatch the tag to an application that can handle the technologies present on the tag.
73+ * Technologies are defined as sub-classes of {@link TagTechnology}, see the package
74+ * {@link android.nfc.tech}. The Android OS looks for an application that can handle one or
75+ * more technologies in the tag. See {@link NfcAdapter#ACTION_TECH_DISCOVERED for more detail.
76+ * <h4>4. Fall-back dispatch</h4>
77+ * If no application has been matched, then {@link Context#startActivity} is called with
78+ * {@link NfcAdapter#ACTION_TAG_DISCOVERED}. This is intended as a fall-back mechanism.
79+ * See {@link NfcAdapter#ACTION_TAG_DISCOVERED}.
80+ *
4081 * <p>
41- * Tag's have a type and usually have a UID.
82+ * <i>The Tag dispatch mechanism was designed to give a high probability of dispatching
83+ * a tag to the correct application without showing the user an Application Chooser dialog.
84+ * This is important for NFC interactions because they are very transient - if a user has to
85+ * move the Android device to choose an application then the connection is broken.</i>
86+ *
87+ * <h3>NFC Tag Background</h3>
88+ * An NFC tag is a passive NFC device, powered by the NFC field of this Android device while
89+ * it is in range. Tag's can come in many forms, such as stickers, cards, key fob, or
90+ * even embedded in a more sophisticated device.
4291 * <p>
43- * {@link Tag} objects are passed to applications via the {@link NfcAdapter#EXTRA_TAG} extra
44- * in {@link NfcAdapter#ACTION_TAG_DISCOVERED} intents. A {@link Tag} object is immutable
45- * and represents the state of the tag at the time of discovery. It can be
46- * directly queried for its UID and Type, or used to create a {@link TagTechnology} using the
47- * static <code>get()</code> methods on the varios tech classes.
92+ * Tags can have a wide range of capabilities. Simple tags just offer read/write semantics,
93+ * and contain some one time
94+ * programmable areas to make read-only. More complex tags offer math operations
95+ * and per-sector access control and authentication. The most sophisticated tags
96+ * contain operating environments such as Javacard, allowing complex interactions with the
97+ * applets executing on the tag. Use {@link TagTechnology} classes to access a broad
98+ * range of capabilities available in NFC tags.
4899 * <p>
49- * A {@link Tag} can be used to create a {@link TagTechnology} only while the tag is in
50- * range. If it is removed and then returned to range, then the most recent
51- * {@link Tag} object (in {@link NfcAdapter#ACTION_TAG_DISCOVERED}) should be used to create a
52- * {@link TagTechnology}.
53- * <p>This is an immutable data class. All properties are set at Tag discovery
54- * time and calls on this class will retrieve those read-only properties, and
55- * not cause any further RF activity or block. Note however that arrays passed to and
56- * returned by this class are *not* cloned, so be careful not to modify them.
57100 */
58101public final class Tag implements Parcelable {
59102 /*package*/ final byte [] mId ;
@@ -149,21 +192,35 @@ public int getServiceHandle() {
149192
150193 /**
151194 * Get the Tag Identifier (if it has one).
152- * <p>Tag ID is usually a serial number for the tag.
153- *
154- * @return ID, or null if it does not exist
195+ * <p>The tag identifier is a low level serial number, used for anti-collision
196+ * and identification.
197+ * <p> Most tags have a stable unique identifier
198+ * (UID), but some tags will generate a random ID every time they are discovered
199+ * (RID), and there are some tags with no ID at all (the byte array will be zero-sized).
200+ * <p> The size and format of an ID is specific to the RF technology used by the tag.
201+ * <p> This function retrieves the ID as determined at discovery time, and does not
202+ * perform any further RF communication or block.
203+ * @return ID as byte array, never null
155204 */
156205 public byte [] getId () {
157206 return mId ;
158207 }
159208
160209 /**
161- * Returns technologies present in the tag that this implementation understands,
162- * or a zero length array if there are no supported technologies on this tag.
163- *
164- * The elements of the list are the names of the classes implementing the technology.
165- *
210+ * Get the technologies available in this tag, as fully qualified class names.
211+ * <p>
212+ * A technology is an implementation of the {@link TagTechnology} interface,
213+ * and can be instantiated by calling the static <code>get(Tag)</code>
214+ * method on the implementation with this Tag. The {@link TagTechnology}
215+ * object can then be used to perform advanced, technology-specific operations on a tag.
216+ * <p>
217+ * Android defines a mandatory set of technologies that must be correctly
218+ * enumerated by all Android NFC devices, and an optional
219+ * set of proprietary technologies.
220+ * See {@link TagTechnology} for more details.
221+ * <p>
166222 * The ordering of the returned array is undefined and should not be relied upon.
223+ * @return an array of fully-qualified {@link TagTechnology} class-names.
167224 */
168225 public String [] getTechList () {
169226 return mTechStringList ;
@@ -176,7 +233,7 @@ public boolean hasTech(int techType) {
176233 }
177234 return false ;
178235 }
179-
236+
180237 /** @hide */
181238 public Bundle getTechExtras (int tech ) {
182239 int pos = -1 ;
@@ -198,6 +255,9 @@ public INfcTag getTagService() {
198255 return mTagService ;
199256 }
200257
258+ /**
259+ * Human-readable description of the tag, for debugging.
260+ */
201261 @ Override
202262 public String toString () {
203263 StringBuilder sb = new StringBuilder ("TAG " )
0 commit comments