# NdefFormatable

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

# NdefFormatable

*** ** * ** ***

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


`
public

final

class
NdefFormatable
`


`

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


`

`


implements

`[TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)`


`

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

<br />

*** ** * ** ***

Provide access to NDEF format operations on a [Tag](https://developer.android.com/reference/android/nfc/Tag).

Acquire a [NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable) object using [get(Tag)](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#get(android.nfc.Tag)).

Android devices with NFC must only enumerate and implement this
class for tags for which it can format to NDEF.

Unfortunately the procedures to convert unformated tags to NDEF formatted
tags are not specified by NFC Forum, and are not generally well-known. So
there is no mandatory set of tags for which all Android devices with NFC
must support [NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable).

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

## Summary

|                                                                                                                                                                                                                               ### Public methods                                                                                                                                                                                                                               ||
|-----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                             | ` `[close](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#close())`() ` Disable I/O operations to the tag from this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object, and release resources.                                                                                                       |
| ` void`                                                                                             | ` `[connect](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#connect())`() ` Enable I/O operations to the tag from this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object.                                                                                                                           |
| ` void`                                                                                             | ` `[format](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#format(android.nfc.NdefMessage))`(`[NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage)` firstMessage) ` Format a tag as NDEF, and write a [NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage).                                  |
| ` void`                                                                                             | ` `[formatReadOnly](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#formatReadOnly(android.nfc.NdefMessage))`(`[NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage)` firstMessage) ` Formats a tag as NDEF, write a [NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage), and make read-only. |
| ` static `[NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable) | ` `[get](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#get(android.nfc.Tag))`(`[Tag](https://developer.android.com/reference/android/nfc/Tag)` tag) ` Get an instance of [NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable) for the given tag.                                                           |
| ` `[Tag](https://developer.android.com/reference/android/nfc/Tag)                                   | ` `[getTag](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#getTag())`() ` Get the [Tag](https://developer.android.com/reference/android/nfc/Tag) object backing this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object.                                                                             |
| ` boolean`                                                                                          | ` `[isConnected](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#isConnected())`() ` Helper to indicate if I/O operations should be possible.                                                                                                                                                                                                     |

| ### 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.nfc.tech.TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology)` ` |----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void`                                                           | ` `[close](https://developer.android.com/reference/android/nfc/tech/TagTechnology#close())`() ` Disable I/O operations to the tag from this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object, and release resources.                           | | ` abstract void`                                                           | ` `[connect](https://developer.android.com/reference/android/nfc/tech/TagTechnology#connect())`() ` Enable I/O operations to the tag from this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object.                                               | | ` abstract `[Tag](https://developer.android.com/reference/android/nfc/Tag) | ` `[getTag](https://developer.android.com/reference/android/nfc/tech/TagTechnology#getTag())`() ` Get the [Tag](https://developer.android.com/reference/android/nfc/Tag) object backing this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object. | | ` abstract boolean`                                                        | ` `[isConnected](https://developer.android.com/reference/android/nfc/tech/TagTechnology#isConnected())`() ` Helper to indicate if I/O operations should be possible.                                                                                                                         | ||
| From interface ` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| From interface ` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Public methods

### 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 [TagTechnology](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 [IOException](https://developer.android.com/reference/java/io/IOException).

Requires the [Manifest.permission.NFC](https://developer.android.com/reference/android/Manifest.permission#NFC) permission.

<br />

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](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 [TagTechnology](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
[IOException](https://developer.android.com/reference/java/io/IOException) by calling [close()](https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()) from another thread.

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

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

Requires the [Manifest.permission.NFC](https://developer.android.com/reference/android/Manifest.permission#NFC) permission.

<br />

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### format

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

```
public void format (NdefMessage firstMessage)
```

Format a tag as NDEF, and write a [NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage).

This is a multi-step process, an IOException is thrown
if any one step fails.

The card is left in a read-write state after this operation.

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
[IOException](https://developer.android.com/reference/java/io/IOException) if [close()](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#close()) is called from another thread.

Requires the [Manifest.permission.NFC](https://developer.android.com/reference/android/Manifest.permission#NFC) permission.

<br />

|                                          Parameters                                           ||
|----------------|-------------------------------------------------------------------------------|
| `firstMessage` | `NdefMessage`: the NDEF message to write after formatting, can be null <br /> |

|                                                                       Throws                                                                       ||
|------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [TagLostException](https://developer.android.com/reference/android/nfc/TagLostException) | if the tag leaves the field                              |
| [IOException](https://developer.android.com/reference/java/io/IOException)               | if there is an I/O failure, or the operation is canceled |
| [FormatException](https://developer.android.com/reference/android/nfc/FormatException)   | if the NDEF Message to write is malformed                |

### formatReadOnly

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

```
public void formatReadOnly (NdefMessage firstMessage)
```

Formats a tag as NDEF, write a [NdefMessage](https://developer.android.com/reference/android/nfc/NdefMessage), and make read-only.

This is a multi-step process, an IOException is thrown
if any one step fails.

The card is left in a read-only state if this method returns successfully.

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
[IOException](https://developer.android.com/reference/java/io/IOException) if [close()](https://developer.android.com/reference/android/nfc/tech/NdefFormatable#close()) is called from another thread.

Requires the [Manifest.permission.NFC](https://developer.android.com/reference/android/Manifest.permission#NFC) permission.

<br />

|                                    Parameters                                    ||
|----------------|------------------------------------------------------------------|
| `firstMessage` | `NdefMessage`: the NDEF message to write after formatting <br /> |

|                                                                         Throws                                                                         ||
|------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [TagLostException](https://developer.android.com/reference/android/nfc/TagLostException) | if the tag leaves the field                                  |
| [IOException](https://developer.android.com/reference/java/io/IOException)               | if there is an I/O failure, or the operation is canceled     |
| [FormatException](https://developer.android.com/reference/android/nfc/FormatException)   | if the NDEF Message to write is malformed                    |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException) | if the tag object is reused after the tag has left the field |

### get

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

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

Get an instance of [NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable) for the given tag.

Does not cause any RF activity and does not block.

Returns null if [NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable) was not enumerated in [Tag.getTechList](https://developer.android.com/reference/android/nfc/Tag#getTechList()).
This indicates the tag is not NDEF formatable by this Android device.

<br />

|                 Parameters                  ||
|-------|--------------------------------------|
| `tag` | `Tag`: an NDEF formatable tag <br /> |

|                                                         Returns                                                          ||
|-------------------------------------------------------------------------------------------|-------------------------------|
| [NdefFormatable](https://developer.android.com/reference/android/nfc/tech/NdefFormatable) | NDEF formatable object <br /> |

### getTag

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

```
public Tag getTag ()
```

Get the [Tag](https://developer.android.com/reference/android/nfc/Tag) object backing this [TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) object.

<br />

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

### 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 [connect()](https://developer.android.com/reference/android/nfc/tech/TagTechnology#connect()) has completed, and [close()](https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()) has not been
called, and the [Tag](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 /> |