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

# MifareClassic

*** ** * ** ***

` public final class MifareClassic `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/nfc/tech/TagTechnology `

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

<br />

*** ** * ** ***

Provides access to MIFARE Classic properties and I/O operations on a `https://developer.android.com/reference/android/nfc/Tag`.

Acquire a `https://developer.android.com/reference/android/nfc/tech/MifareClassic` object using `https://developer.android.com/reference/android/nfc/tech/MifareClassic#get(android.nfc.Tag)`.

MIFARE Classic is also known as MIFARE Standard.

MIFARE Classic tags are divided into sectors, and each sector is sub-divided into blocks. Block size is always 16 bytes (`https://developer.android.com/reference/android/nfc/tech/MifareClassic#BLOCK_SIZE`. Sector size varies.

- MIFARE Classic Mini are 320 bytes (`https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_MINI`), with 5 sectors each of 4 blocks.
- MIFARE Classic 1k are 1024 bytes (`https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_1K`), with 16 sectors each of 4 blocks.
- MIFARE Classic 2k are 2048 bytes (`https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_2K`), with 32 sectors each of 4 blocks.
- MIFARE Classic 4k are 4096 bytes (`https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_4K`). The first 32 sectors contain 4 blocks and the last 8 sectors contain 16 blocks.

MIFARE Classic tags require authentication on a per-sector basis before any other I/O operations on that sector can be performed. There are two keys per sector, and ACL bits determine what I/O operations are allowed on that sector after authenticating with a key. See `https://developer.android.com/reference/android/nfc/tech/MifareClassic#authenticateSectorWithKeyA(int,%20byte[])` and `https://developer.android.com/reference/android/nfc/tech/MifareClassic#authenticateSectorWithKeyB(int,%20byte[])`.

Three well-known authentication keys are defined in this class: `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_DEFAULT`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_MIFARE_APPLICATION_DIRECTORY`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_NFC_FORUM`.

- `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_DEFAULT` is the default factory key for MIFARE Classic.
- `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_MIFARE_APPLICATION_DIRECTORY` is the well-known key for MIFARE Classic cards that have been formatted according to the MIFARE Application Directory (MAD) specification.
- `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_NFC_FORUM` is the well-known key for MIFARE Classic cards that have been formatted according to the NXP specification for NDEF on MIFARE Classic.

  Implementation of this class on a Android NFC device is optional. If it is not implemented, then `https://developer.android.com/reference/android/nfc/tech/MifareClassic` will never be enumerated in `https://developer.android.com/reference/android/nfc/Tag#getTechList()`. If it is enumerated, then all `https://developer.android.com/reference/android/nfc/tech/MifareClassic` I/O operations will be supported, and `https://developer.android.com/reference/android/nfc/tech/Ndef#MIFARE_CLASSIC` NDEF tags will also be supported. In either case, `https://developer.android.com/reference/android/nfc/tech/NfcA` will also be enumerated on the tag, because all MIFARE Classic tags are also `https://developer.android.com/reference/android/nfc/tech/NfcA`.

  **Note:** Methods that perform I/O operations require the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  ## Summary

  | ### Constants ||
  |---|---|
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#BLOCK_SIZE` Size of a MIFARE Classic block (in bytes) |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_1K` Tag contains 16 sectors, each with 4 blocks. |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_2K` Tag contains 32 sectors, each with 4 blocks. |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_4K` Tag contains 40 sectors. |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_MINI` Tag contains 5 sectors, each with 4 blocks. |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_CLASSIC` A MIFARE Classic tag |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_PLUS` A MIFARE Plus tag |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_PRO` A MIFARE Pro tag |
  | `int` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_UNKNOWN` A MIFARE Classic compatible card of unknown type |

  | ### Fields ||
  |---|---|
  | ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_DEFAULT` The default factory key. |
  | ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_MIFARE_APPLICATION_DIRECTORY` The well-known key for tags formatted according to the MIFARE Application Directory (MAD) specification. |
  | ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/tech/MifareClassic#KEY_NFC_FORUM` The well-known key for tags formatted according to the NDEF on MIFARE Classic specification. |

  | ### Public methods ||
  |---|---|
  | ` boolean` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#authenticateSectorWithKeyA(int,%20byte[])(int sectorIndex, byte[] key) ` Authenticate a sector with key A. |
  | ` boolean` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#authenticateSectorWithKeyB(int,%20byte[])(int sectorIndex, byte[] key) ` Authenticate a sector with key B. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#blockToSector(int)(int blockIndex) ` Return the sector that contains a given block. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()() ` Disable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object, and release resources. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#connect()() ` Enable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#decrement(int,%20int)(int blockIndex, int value) ` Decrement a value block, storing the result in the temporary block on the tag. |
  | ` static https://developer.android.com/reference/android/nfc/tech/MifareClassic` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#get(android.nfc.Tag)(https://developer.android.com/reference/android/nfc/Tag tag) ` Get an instance of `https://developer.android.com/reference/android/nfc/tech/MifareClassic` for the given tag. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getBlockCount()() ` Return the total number of MIFARE Classic blocks. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getBlockCountInSector(int)(int sectorIndex) ` Return the number of blocks in the given sector. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getMaxTransceiveLength()() ` Return the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])`. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getSectorCount()() ` Return the number of MIFARE Classic sectors. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getSize()() ` Return the size of the tag in bytes One of `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_MINI`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_1K`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_2K`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_4K`. |
  | ` https://developer.android.com/reference/android/nfc/Tag` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getTag()() ` Get the `https://developer.android.com/reference/android/nfc/Tag` object backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getTimeout()() ` Get the current `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])` timeout in milliseconds. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#getType()() ` Return the type of this MIFARE Classic compatible tag. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#increment(int,%20int)(int blockIndex, int value) ` Increment a value block, storing the result in the temporary block on the tag. |
  | ` boolean` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#isConnected()() ` Helper to indicate if I/O operations should be possible. |
  | ` byte[]` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#readBlock(int)(int blockIndex) ` Read 16-byte block. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#restore(int)(int blockIndex) ` Copy from a value block to the temporary block. |
  | ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#sectorToBlock(int)(int sectorIndex) ` Return the first block of a given sector. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#setTimeout(int)(int timeout) ` Set the `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])` timeout in milliseconds. |
  | ` byte[]` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])(byte[] data) ` Send raw NfcA data to a tag and receive the response. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#transfer(int)(int blockIndex) ` Copy from the temporary block to a value block. |
  | ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareClassic#writeBlock(int,%20byte[])(int blockIndex, byte[] data) ` Write 16-byte block. |

  ### Inherited methods

  From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

  Creates and returns a copy of this object.
  ` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

  Indicates whether some other object is "equal to" this one.
  ` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

  Returns the runtime class of this `Object`.
  ` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

  Returns a hash code value for the object.
  ` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

  Wakes up a single thread that is waiting on this object's monitor.
  ` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

  Wakes up all threads that are waiting on this object's monitor.
  ` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

  Returns a string representation of the object.
  ` final void` ` 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` ` 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` ` 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 ` https://developer.android.com/reference/android/nfc/tech/TagTechnology ` ` abstract void` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()() `

  Disable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object, and release resources.
  ` abstract void` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#connect()() `

  Enable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.
  ` abstract https://developer.android.com/reference/android/nfc/Tag` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#getTag()() `

  Get the `https://developer.android.com/reference/android/nfc/Tag` object backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.
  ` abstract boolean` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#isConnected()() `

  Helper to indicate if I/O operations should be possible.
  From interface ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

  Closes this stream and releases any system resources associated with it.
  From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

  Closes this resource, relinquishing any underlying resources.

  ## Constants

  ### BLOCK_SIZE

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

  ```
  public static final int BLOCK_SIZE
  ```

  Size of a MIFARE Classic block (in bytes)

  <br />

  Constant Value: 16 (0x00000010)

  ### SIZE_1K

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

  ```
  public static final int SIZE_1K
  ```

  Tag contains 16 sectors, each with 4 blocks.

  <br />

  Constant Value: 1024 (0x00000400)

  ### SIZE_2K

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

  ```
  public static final int SIZE_2K
  ```

  Tag contains 32 sectors, each with 4 blocks.

  <br />

  Constant Value: 2048 (0x00000800)

  ### SIZE_4K

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

  ```
  public static final int SIZE_4K
  ```

  Tag contains 40 sectors. The first 32 sectors contain 4 blocks and the last 8 sectors contain 16 blocks.

  <br />

  Constant Value: 4096 (0x00001000)

  ### SIZE_MINI

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

  ```
  public static final int SIZE_MINI
  ```

  Tag contains 5 sectors, each with 4 blocks.

  <br />

  Constant Value: 320 (0x00000140)

  ### TYPE_CLASSIC

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

  ```
  public static final int TYPE_CLASSIC
  ```

  A MIFARE Classic tag

  <br />

  Constant Value: 0 (0x00000000)

  ### TYPE_PLUS

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

  ```
  public static final int TYPE_PLUS
  ```

  A MIFARE Plus tag

  <br />

  Constant Value: 1 (0x00000001)

  ### TYPE_PRO

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

  ```
  public static final int TYPE_PRO
  ```

  A MIFARE Pro tag

  <br />

  Constant Value: 2 (0x00000002)

  ### TYPE_UNKNOWN

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

  ```
  public static final int TYPE_UNKNOWN
  ```

  A MIFARE Classic compatible card of unknown type

  <br />

  Constant Value: -1 (0xffffffff)

  ## Fields

  ### KEY_DEFAULT

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

  ```
  public static final byte[] KEY_DEFAULT
  ```

  The default factory key.

  <br />

  ### KEY_MIFARE_APPLICATION_DIRECTORY

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

  ```
  public static final byte[] KEY_MIFARE_APPLICATION_DIRECTORY
  ```

  The well-known key for tags formatted according to the MIFARE Application Directory (MAD) specification.

  <br />

  ### KEY_NFC_FORUM

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

  ```
  public static final byte[] KEY_NFC_FORUM
  ```

  The well-known key for tags formatted according to the NDEF on MIFARE Classic specification.

  <br />

  ## Public methods

  ### authenticateSectorWithKeyA

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

  ```
  public boolean authenticateSectorWithKeyA (int sectorIndex, 
                  byte[] key)
  ```

  Authenticate a sector with key A.

  Successful authentication of a sector with key A enables other I/O operations on that sector. The set of operations granted by key A key depends on the ACL bits set in that sector. For more information see the MIFARE Classic specification on <http://www.nxp.com>.

  A failed authentication attempt causes an implicit reconnection to the tag, so authentication to other sectors will be lost.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `sectorIndex` | `int`: index of sector to authenticate, starting from 0 <br /> |
  | `key` | `byte`: 6-byte authentication key <br /> |

  | Returns ||
  |---|---|
  | `boolean` | true on success, false on authentication failure <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### authenticateSectorWithKeyB

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

  ```
  public boolean authenticateSectorWithKeyB (int sectorIndex, 
                  byte[] key)
  ```

  Authenticate a sector with key B.

  Successful authentication of a sector with key B enables other I/O operations on that sector. The set of operations granted by key B depends on the ACL bits set in that sector. For more information see the MIFARE Classic specification on <http://www.nxp.com>.

  A failed authentication attempt causes an implicit reconnection to the tag, so authentication to other sectors will be lost.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `sectorIndex` | `int`: index of sector to authenticate, starting from 0 <br /> |
  | `key` | `byte`: 6-byte authentication key <br /> |

  | Returns ||
  |---|---|
  | `boolean` | true on success, false on authentication failure <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### blockToSector

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

  ```
  public int blockToSector (int blockIndex)
  ```

  Return the sector that contains a given block.

  Does not cause any RF activity and does not block.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to lookup, starting from 0 <br /> |

  | Returns ||
  |---|---|
  | `int` | sector index that contains the block <br /> |

  ### close

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

  ```
  public void close ()
  ```

  Disable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object, and release resources.

  Also causes all blocked I/O operations on other thread to be canceled and return with `https://developer.android.com/reference/java/io/IOException`.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/java/io/IOException` |   |

  ### connect

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

  ```
  public void connect ()
  ```

  Enable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.

  May cause RF activity and may block. Must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` by calling `https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()` from another thread.

  Only one `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object can be connected to a `https://developer.android.com/reference/android/nfc/Tag` at a time.

  Applications must call `https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()` when I/O operations are complete.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/java/io/IOException` |   |

  ### decrement

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

  ```
  public void decrement (int blockIndex, 
                  int value)
  ```

  Decrement a value block, storing the result in the temporary block on the tag.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to decrement, starting from 0 <br /> |
  | `value` | `int`: non-negative to decrement by <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### get

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

  ```
  public static MifareClassic get (Tag tag)
  ```

  Get an instance of `https://developer.android.com/reference/android/nfc/tech/MifareClassic` for the given tag.

  Does not cause any RF activity and does not block.

  Returns null if `https://developer.android.com/reference/android/nfc/tech/MifareClassic` was not enumerated in `https://developer.android.com/reference/android/nfc/Tag#getTechList()`. This indicates the tag is not MIFARE Classic compatible, or this Android device does not support MIFARE Classic.

  <br />

  | Parameters ||
  |---|---|
  | `tag` | `Tag`: an MIFARE Classic compatible tag <br /> |

  | Returns ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/tech/MifareClassic` | MIFARE Classic object <br /> |

  ### getBlockCount

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

  ```
  public int getBlockCount ()
  ```

  Return the total number of MIFARE Classic blocks.

  Does not cause any RF activity and does not block.

  <br />

  | Returns ||
  |---|---|
  | `int` | total number of blocks <br /> |

  ### getBlockCountInSector

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

  ```
  public int getBlockCountInSector (int sectorIndex)
  ```

  Return the number of blocks in the given sector.

  Does not cause any RF activity and does not block.

  <br />

  | Parameters ||
  |---|---|
  | `sectorIndex` | `int`: index of sector, starting from 0 <br /> |

  | Returns ||
  |---|---|
  | `int` | number of blocks in the sector <br /> |

  ### getMaxTransceiveLength

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

  ```
  public int getMaxTransceiveLength ()
  ```

  Return the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])`.

  <br />

  | Returns ||
  |---|---|
  | `int` | the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])`. <br /> |

  ### getSectorCount

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

  ```
  public int getSectorCount ()
  ```

  Return the number of MIFARE Classic sectors.

  Does not cause any RF activity and does not block.

  <br />

  | Returns ||
  |---|---|
  | `int` | number of sectors <br /> |

  ### getSize

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

  ```
  public int getSize ()
  ```

  Return the size of the tag in bytes

  One of `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_MINI`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_1K`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_2K`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#SIZE_4K`. These constants are equal to their respective size in bytes.

  Does not cause any RF activity and does not block.

  <br />

  | Returns ||
  |---|---|
  | `int` | size in bytes <br /> |

  ### getTag

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

  ```
  public Tag getTag ()
  ```

  Get the `https://developer.android.com/reference/android/nfc/Tag` object backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.

  <br />

  | Returns ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/Tag` | the `https://developer.android.com/reference/android/nfc/Tag` backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object. <br /> |

  ### getTimeout

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

  ```
  public int getTimeout ()
  ```

  Get the current `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])` timeout in milliseconds.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Returns ||
  |---|---|
  | `int` | timeout value in milliseconds <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/java/lang/SecurityException` | if the tag object is reused after the tag has left the field |

  ### getType

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

  ```
  public int getType ()
  ```

  Return the type of this MIFARE Classic compatible tag.

  One of `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_UNKNOWN`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_CLASSIC`, `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_PLUS` or `https://developer.android.com/reference/android/nfc/tech/MifareClassic#TYPE_PRO`.

  Does not cause any RF activity and does not block.

  <br />

  | Returns ||
  |---|---|
  | `int` | type <br /> |

  ### increment

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

  ```
  public void increment (int blockIndex, 
                  int value)
  ```

  Increment a value block, storing the result in the temporary block on the tag.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to increment, starting from 0 <br /> |
  | `value` | `int`: non-negative to increment by <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### isConnected

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

  ```
  public boolean isConnected ()
  ```

  Helper to indicate if I/O operations should be possible.

  Returns true if `https://developer.android.com/reference/android/nfc/tech/TagTechnology#connect()` has completed, and `https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()` has not been called, and the `https://developer.android.com/reference/android/nfc/Tag` is not known to be out of range.

  Does not cause RF activity, and does not block.

  <br />

  | Returns ||
  |---|---|
  | `boolean` | true if I/O operations should be possible <br /> |

  ### readBlock

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

  ```
  public byte[] readBlock (int blockIndex)
  ```

  Read 16-byte block.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to read, starting from 0 <br /> |

  | Returns ||
  |---|---|
  | `byte[]` | 16 byte block <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### restore

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

  ```
  public void restore (int blockIndex)
  ```

  Copy from a value block to the temporary block.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to copy from <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### sectorToBlock

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

  ```
  public int sectorToBlock (int sectorIndex)
  ```

  Return the first block of a given sector.

  Does not cause any RF activity and does not block.

  <br />

  | Parameters ||
  |---|---|
  | `sectorIndex` | `int`: index of sector to lookup, starting from 0 <br /> |

  | Returns ||
  |---|---|
  | `int` | block index of first block in sector <br /> |

  ### setTimeout

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

  ```
  public void setTimeout (int timeout)
  ```

  Set the `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])` timeout in milliseconds.

  The timeout only applies to `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])` on this object, and is reset to a default value when `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called.

  Setting a longer timeout may be useful when performing transactions that require a long processing time on the tag such as key generation.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `timeout` | `int`: timeout value in milliseconds <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/java/lang/SecurityException` | if the tag object is reused after the tag has left the field |

  ### transceive

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

  ```
  public byte[] transceive (byte[] data)
  ```

  Send raw NfcA data to a tag and receive the response.

  This is equivalent to connecting to this tag via `https://developer.android.com/reference/android/nfc/tech/NfcA` and calling `https://developer.android.com/reference/android/nfc/tech/NfcA#transceive(byte[])`. Note that all MIFARE Classic tags are based on `https://developer.android.com/reference/android/nfc/tech/NfcA` technology.

  Use `https://developer.android.com/reference/android/nfc/tech/MifareClassic#getMaxTransceiveLength()` to retrieve the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareClassic#transceive(byte[])`.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `data` | `byte` <br /> |

  | Returns ||
  |---|---|
  | `byte[]` | <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/java/io/IOException` |   |

  **See also:**
  - `https://developer.android.com/reference/android/nfc/tech/NfcA#transceive(byte[])`

  ### transfer

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

  ```
  public void transfer (int blockIndex)
  ```

  Copy from the temporary block to a value block.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to copy to <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

  ### writeBlock

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

  ```
  public void writeBlock (int blockIndex, 
                  byte[] data)
  ```

  Write 16-byte block.

  This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareClassic#close()` is called from another thread.

  Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

  <br />

  | Parameters ||
  |---|---|
  | `blockIndex` | `int`: index of block to write, starting from 0 <br /> |
  | `data` | `byte`: 16 bytes of data to write <br /> |

  | Throws ||
  |---|---|
  | `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
  | `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |