# Tag

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Inherited Constants](https://developer.android.com/reference/android/nfc/Tag#inhconstants)\|[Fields](https://developer.android.com/reference/android/nfc/Tag#lfields)\|[Methods](https://developer.android.com/reference/android/nfc/Tag#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/nfc/Tag#inhmethods)  

# Tag

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/nfc/Tag "View this page in Kotlin")\|Java

`
public

final

class
Tag
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Parcelable](https://developer.android.com/reference/android/os/Parcelable)`


`

|---|-----------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.nfc.Tag |

<br />

*** ** * ** ***

Represents an NFC tag that has been discovered.

[Tag](https://developer.android.com/reference/android/nfc/Tag)is an immutable object that represents the state of a NFC tag at the time of discovery. It can be used as a handle to[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)classes to perform advanced operations, or directly queried for its ID via[getId()](https://developer.android.com/reference/android/nfc/Tag#getId())and the set of technologies it contains via[getTechList()](https://developer.android.com/reference/android/nfc/Tag#getTechList()). Arrays passed to and returned by this class are*not*cloned, so be careful not to modify them.

A new tag object is created every time a tag is discovered (comes into range), even if it is the same physical tag. If a tag is removed and then returned into range, then only the most recent tag object can be successfully used to create a[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology).

### Tag Dispatch

When a tag is discovered, a[Tag](https://developer.android.com/reference/android/nfc/Tag)object is created and passed to a single activity via the[NfcAdapter.EXTRA_TAG](https://developer.android.com/reference/android/nfc/NfcAdapter#EXTRA_TAG)extra in an[Intent](https://developer.android.com/reference/android/content/Intent)via[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)). A four stage dispatch is used to select the most appropriate activity to handle the tag. The Android OS executes each stage in order, and completes dispatch as soon as a single matching activity is found. If there are multiple matching activities found at any one stage then the Android activity chooser dialog is shown to allow the user to select the activity to receive the tag.

The Tag dispatch mechanism was designed to give a high probability of dispatching a tag to the correct activity without showing the user an activity chooser dialog. This is important for NFC interactions because they are very transient -- if a user has to move the Android device to choose an application then the connection will likely be broken.

#### 1. Foreground activity dispatch

A foreground activity that has called[NfcAdapter.enableForegroundDispatch()](https://developer.android.com/reference/android/nfc/NfcAdapter#enableForegroundDispatch(android.app.Activity,%20android.app.PendingIntent,%20android.content.IntentFilter[],%20java.lang.String[][]))is given priority. See the documentation on[NfcAdapter.enableForegroundDispatch()](https://developer.android.com/reference/android/nfc/NfcAdapter#enableForegroundDispatch(android.app.Activity,%20android.app.PendingIntent,%20android.content.IntentFilter[],%20java.lang.String[][]))for its usage.

#### 2. NDEF data dispatch

If the tag contains NDEF data the system inspects the first[NdefRecord](https://developer.android.com/reference/android/nfc/NdefRecord)in the first[NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage). If the record is a URI, SmartPoster, or MIME data[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))is called with[NfcAdapter.ACTION_NDEF_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_NDEF_DISCOVERED). For URI and SmartPoster records the URI is put into the intent's data field. For MIME records the MIME type is put in the intent's type field. This allows activities to register to be launched only when data they know how to handle is present on a tag. This is the preferred method of handling data on a tag since NDEF data can be stored on many types of tags and doesn't depend on a specific tag technology. See[NfcAdapter.ACTION_NDEF_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_NDEF_DISCOVERED)for more detail. If the tag does not contain NDEF data, or if no activity is registered for[NfcAdapter.ACTION_NDEF_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_NDEF_DISCOVERED)with a matching data URI or MIME type then dispatch moves to stage 3.

#### 3. Tag Technology dispatch

[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))is called with[NfcAdapter.ACTION_TECH_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_TECH_DISCOVERED)to dispatch the tag to an activity that can handle the technologies present on the tag. Technologies are defined as sub-classes of[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology), see the package[android.nfc.tech](https://developer.android.com/reference/android/nfc/tech/package-summary). The Android OS looks for an activity that can handle one or more technologies in the tag. See[NfcAdapter.ACTION_TECH_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_TECH_DISCOVERED)for more detail.

#### 4. Fall-back dispatch

If no activity has been matched then[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))is called with[NfcAdapter.ACTION_TAG_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_TAG_DISCOVERED). This is intended as a fall-back mechanism. See[NfcAdapter.ACTION_TAG_DISCOVERED](https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_TAG_DISCOVERED).

### NFC Tag Background

An NFC tag is a passive NFC device, powered by the NFC field of this Android device while it is in range. Tag's can come in many forms, such as stickers, cards, key fobs, or even embedded in a more sophisticated device.

Tags can have a wide range of capabilities. Simple tags just offer read/write semantics, and contain some one time programmable areas to make read-only. More complex tags offer math operations and per-sector access control and authentication. The most sophisticated tags contain operating environments allowing complex interactions with the code executing on the tag. Use[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)classes to access a broad range of capabilities available in NFC tags.

<br />

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ### Inherited constants                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From interface[android.os.Parcelable](https://developer.android.com/reference/android/os/Parcelable) |-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `int` | [CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR) Descriptor bit used with[describeContents()](https://developer.android.com/reference/android/os/Parcelable#describeContents()): indicates that the Parcelable object's flattened representation includes a file descriptor.                                                                                                                                            | | `int` | [PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE) Flag for use with[writeToParcel(Parcel, int)](https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)): the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`". | |

|                                                                                                                           ### Fields                                                                                                                           ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| ` public static final `[Creator](https://developer.android.com/reference/android/os/Parcelable.Creator)`<`[Tag](https://developer.android.com/reference/android/nfc/Tag)`>` | [CREATOR](https://developer.android.com/reference/android/nfc/Tag#CREATOR) <br /> |

|                                                                                                                                                     ### Public methods                                                                                                                                                     ||
|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`                                                                  | ` `[describeContents](https://developer.android.com/reference/android/nfc/Tag#describeContents())`() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.                                    |
| ` byte[]`                                                               | ` `[getId](https://developer.android.com/reference/android/nfc/Tag#getId())`() ` Get the Tag Identifier (if it has one).                                                                                                                          |
| ` `[String[]](https://developer.android.com/reference/java/lang/String) | ` `[getTechList](https://developer.android.com/reference/android/nfc/Tag#getTechList())`() ` Get the technologies available in this tag, as fully qualified class names.                                                                          |
| ` `[String](https://developer.android.com/reference/java/lang/String)   | ` `[toString](https://developer.android.com/reference/android/nfc/Tag#toString())`() ` Human-readable description of the tag, for debugging.                                                                                                      |
| ` void`                                                                 | ` `[writeToParcel](https://developer.android.com/reference/android/nfc/Tag#writeToParcel(android.os.Parcel,%20int))`(`[Parcel](https://developer.android.com/reference/android/os/Parcel)` dest, int flags) ` Flatten this object in to a Parcel. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[android.os.Parcelable](https://developer.android.com/reference/android/os/Parcelable)` ` |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract int`  | ` `[describeContents](https://developer.android.com/reference/android/os/Parcelable#describeContents())`() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.                                    | | ` abstract void` | ` `[writeToParcel](https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int))`(`[Parcel](https://developer.android.com/reference/android/os/Parcel)` dest, int flags) ` Flatten this object in to a Parcel. | ||

## Fields

### CREATOR

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Creator<Tag> CREATOR
```

<br />

<br />

## Public methods

### describeContents

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of[writeToParcel(android.os.Parcel, int)](https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)), the return value of this method must include the[CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR)bit.

<br />

|                                                                                                                         Returns                                                                                                                         ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either`0`or[CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR) <br /> |

### getId

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public byte[] getId ()
```

Get the Tag Identifier (if it has one).

The tag identifier is a low level serial number, used for anti-collision and identification.

Most tags have a stable unique identifier (UID), but some tags will generate a random ID every time they are discovered (RID), and there are some tags with no ID at all (the byte array will be zero-sized).

The size and format of an ID is specific to the RF technology used by the tag.

This function retrieves the ID as determined at discovery time, and does not perform any further RF communication or block.

<br />

|                    Returns                    ||
|----------|-------------------------------------|
| `byte[]` | ID as byte array, never null <br /> |

### getTechList

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String[] getTechList ()
```

Get the technologies available in this tag, as fully qualified class names.

A technology is an implementation of the[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)interface, and can be instantiated by calling the static`get(Tag)`method on the implementation with this Tag. The[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)object can then be used to perform advanced, technology-specific operations on a tag.

Android defines a mandatory set of technologies that must be correctly enumerated by all Android NFC devices, and an optional set of proprietary technologies. See[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)for more details.

The ordering of the returned array is undefined and should not be relied upon.

<br />

|                                                                                                   Returns                                                                                                   ||
|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| [String[]](https://developer.android.com/reference/java/lang/String) | an array of fully-qualified[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)class-names. <br /> |

### toString

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Human-readable description of the tag, for debugging.

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |

### writeToParcel

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void writeToParcel (Parcel dest, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

|                                                                                                                                                                                                                               Parameters                                                                                                                                                                                                                                ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dest`  | `Parcel`: The Parcel in which the object should be written. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                 |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or[Parcelable.PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE). Value is either`0`or a combination of[Parcelable.PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE), and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES <br /> |