Freigeben über


Tag Class

Definition

Represents an NFC tag that has been discovered.

[Android.Runtime.Register("android/nfc/Tag", DoNotGenerateAcw=true)]
public sealed class Tag : Java.Lang.Object, Android.OS.IParcelable, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("android/nfc/Tag", DoNotGenerateAcw=true)>]
type Tag = class
    inherit Object
    interface IParcelable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
Attributes
Implements

Remarks

Represents an NFC tag that has been discovered.

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 classes to perform advanced operations, or directly queried for its ID via #getId and the set of technologies it contains via #getTechList. Arrays passed to and returned by this class are <em>not</em> 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.

<h3>Tag Dispatch</h3> When a tag is discovered, a Tag object is created and passed to a single activity via the NfcAdapter#EXTRA_TAG extra in an android.content.Intent via Context#startActivity. 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.

<h4>1. Foreground activity dispatch</h4> A foreground activity that has called NfcAdapter#enableForegroundDispatch NfcAdapter.enableForegroundDispatch() is given priority. See the documentation on NfcAdapter#enableForegroundDispatch NfcAdapter.enableForegroundDispatch() for its usage. <h4>2. NDEF data dispatch</h4> If the tag contains NDEF data the system inspects the first NdefRecord in the first NdefMessage. If the record is a URI, SmartPoster, or MIME data Context#startActivity is called with 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 for more detail. If the tag does not contain NDEF data, or if no activity is registered for NfcAdapter#ACTION_NDEF_DISCOVERED with a matching data URI or MIME type then dispatch moves to stage 3. <h4>3. Tag Technology dispatch</h4> Context#startActivity is called with 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, see the package android.nfc.tech. The Android OS looks for an activity that can handle one or more technologies in the tag. See NfcAdapter#ACTION_TECH_DISCOVERED for more detail. <h4>4. Fall-back dispatch</h4> If no activity has been matched then Context#startActivity is called with NfcAdapter#ACTION_TAG_DISCOVERED. This is intended as a fall-back mechanism. See NfcAdapter#ACTION_TAG_DISCOVERED.

<h3>NFC Tag Background</h3> 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 classes to access a broad range of capabilities available in NFC tags.

Java documentation for android.nfc.Tag.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Creator
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
DescribeContents()

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetId()

Get the Tag Identifier (if it has one).

GetTechList()

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

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
WriteToParcel(Parcel, ParcelableWriteFlags)

Flatten this object in to a Parcel.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to