Android 2.3 Gingerbread

android.nfc
Class NfcAdapter

java.lang.Object
  extended by android.nfc.NfcAdapter

public final class NfcAdapter
extends Object

Represents the device's local NFC adapter.

Use the static getDefaultAdapter() method to get the default NFC Adapter for this Android device. Most Android devices will have only one NFC Adapter, and getDefaultAdapter() returns the singleton object.


Field Summary
static String ACTION_ADAPTER_STATE_CHANGE
          Broadcast Action: an adapter's state changed between enabled and disabled.
static String ACTION_LLCP_LINK_STATE_CHANGED
          Broadcast Action: the LLCP link state changed.
static String ACTION_TAG_DISCOVERED
          Intent to start an activity when a tag is discovered.
static String ACTION_TRANSACTION_DETECTED
          Broadcast Action: a transaction with a secure element has been detected.
static String EXTRA_AID
          Mandatory byte array extra field in ACTION_TRANSACTION_DETECTED.
static String EXTRA_ID
          Optional byte[] extra for the tag identifier.
static String EXTRA_LLCP_LINK_STATE_CHANGED
          Used as int extra field in ACTION_LLCP_LINK_STATE_CHANGED.
static String EXTRA_NDEF_MESSAGES
          Optional NdefMessage[] extra for the ACTION_TAG intents.
static String EXTRA_NEW_BOOLEAN_STATE
          The Intent extra for ACTION_ADAPTER_STATE_CHANGE, saying what the new state is.
static String EXTRA_TAG
          Mandatory Tag extra for the ACTION_TAG intents.
static int LLCP_LINK_STATE_ACTIVATED
          LLCP link status: The LLCP link is activated.
static int LLCP_LINK_STATE_DEACTIVATED
          LLCP link status: The LLCP link is deactivated.
(package private)  android.nfc.INfcAdapter mService
           
 
Method Summary
(package private)  void attemptDeadServiceRecovery(Exception e)
          NFC service dead - attempt best effort recovery
 NdefTagConnection createNdefTagConnection(NdefTag tag)
          Create an NDEF tag connection to the default Target
 NdefTagConnection createNdefTagConnection(NdefTag tag, String target)
          Create an NDEF tag connection to the specified Target
 RawTagConnection createRawTagConnection(Tag tag)
          Create a raw tag connection to the default Target
 RawTagConnection createRawTagConnection(Tag tag, String target)
          Create a raw tag connection to the specified Target
 boolean disable()
          Disable NFC hardware.
 boolean enable()
          Enable NFC hardware.
static NfcAdapter getDefaultAdapter()
          Get a handle to the default NFC Adapter on this Android device.
 boolean isEnabled()
          Return true if this NFC Adapter has any features enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_TAG_DISCOVERED

public static final String ACTION_TAG_DISCOVERED
Intent to start an activity when a tag is discovered.

See Also:
Constant Field Values

EXTRA_TAG

public static final String EXTRA_TAG
Mandatory Tag extra for the ACTION_TAG intents.

See Also:
Constant Field Values

EXTRA_NDEF_MESSAGES

public static final String EXTRA_NDEF_MESSAGES
Optional NdefMessage[] extra for the ACTION_TAG intents.

See Also:
Constant Field Values

EXTRA_ID

public static final String EXTRA_ID
Optional byte[] extra for the tag identifier.

See Also:
Constant Field Values

ACTION_TRANSACTION_DETECTED

public static final String ACTION_TRANSACTION_DETECTED
Broadcast Action: a transaction with a secure element has been detected.

Always contains the extra field EXTRA_AID

See Also:
Constant Field Values

ACTION_ADAPTER_STATE_CHANGE

public static final String ACTION_ADAPTER_STATE_CHANGE
Broadcast Action: an adapter's state changed between enabled and disabled. The new value is stored in the extra EXTRA_NEW_BOOLEAN_STATE and just contains whether it's enabled or disabled, not including any information about whether it's actively enabling or disabling.

See Also:
Constant Field Values

EXTRA_NEW_BOOLEAN_STATE

public static final String EXTRA_NEW_BOOLEAN_STATE
The Intent extra for ACTION_ADAPTER_STATE_CHANGE, saying what the new state is.

See Also:
Constant Field Values

EXTRA_AID

public static final String EXTRA_AID
Mandatory byte array extra field in ACTION_TRANSACTION_DETECTED.

Contains the AID of the applet involved in the transaction.

See Also:
Constant Field Values

LLCP_LINK_STATE_ACTIVATED

public static final int LLCP_LINK_STATE_ACTIVATED
LLCP link status: The LLCP link is activated.

See Also:
Constant Field Values

LLCP_LINK_STATE_DEACTIVATED

public static final int LLCP_LINK_STATE_DEACTIVATED
LLCP link status: The LLCP link is deactivated.

See Also:
Constant Field Values

ACTION_LLCP_LINK_STATE_CHANGED

public static final String ACTION_LLCP_LINK_STATE_CHANGED
Broadcast Action: the LLCP link state changed.

Always contains the extra field EXTRA_LLCP_LINK_STATE_CHANGED.

See Also:
Constant Field Values

EXTRA_LLCP_LINK_STATE_CHANGED

public static final String EXTRA_LLCP_LINK_STATE_CHANGED
Used as int extra field in ACTION_LLCP_LINK_STATE_CHANGED.

It contains the new state of the LLCP link.

See Also:
Constant Field Values

mService

android.nfc.INfcAdapter mService
Method Detail

getDefaultAdapter

public static NfcAdapter getDefaultAdapter()
Get a handle to the default NFC Adapter on this Android device.

Most Android devices will only have one NFC Adapter (NFC Controller).

Returns:
the default NFC adapter, or null if no NFC adapter exists

attemptDeadServiceRecovery

void attemptDeadServiceRecovery(Exception e)
NFC service dead - attempt best effort recovery


isEnabled

public boolean isEnabled()
Return true if this NFC Adapter has any features enabled.

If this method returns false, then applications should request the user turn on NFC tag discovery in Settings.

If this method returns false, the NFC hardware is guaranteed not to perform or respond to any NFC communication.

Returns:
true if this NFC Adapter is enabled to discover new tags

enable

public boolean enable()
Enable NFC hardware.

NOTE: may block for ~second or more. Poor API. Avoid calling from the UI thread.


disable

public boolean disable()
Disable NFC hardware. No NFC features will work after this call, and the hardware will not perform or respond to any NFC communication.

NOTE: may block for ~second or more. Poor API. Avoid calling from the UI thread.


createRawTagConnection

public RawTagConnection createRawTagConnection(Tag tag)
Create a raw tag connection to the default Target

Requires Manifest.permission.NFC permission.


createRawTagConnection

public RawTagConnection createRawTagConnection(Tag tag,
                                               String target)
Create a raw tag connection to the specified Target

Requires Manifest.permission.NFC permission.


createNdefTagConnection

public NdefTagConnection createNdefTagConnection(NdefTag tag)
Create an NDEF tag connection to the default Target

Requires Manifest.permission.NFC permission.


createNdefTagConnection

public NdefTagConnection createNdefTagConnection(NdefTag tag,
                                                 String target)
Create an NDEF tag connection to the specified Target

Requires Manifest.permission.NFC permission.


Android 2.3 Gingerbread