# ClipboardManager

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/content/ClipboardManager#nestedclasses)\|[Methods](https://developer.android.com/reference/android/content/ClipboardManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/content/ClipboardManager#inhmethods)  

# ClipboardManager

*** ** * ** ***

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

`
public


class
ClipboardManager
`  
`


``

extends `[ClipboardManager](https://developer.android.com/reference/android/text/ClipboardManager)`


``


`

|---|---|----------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.text.ClipboardManager](https://developer.android.com/reference/android/text/ClipboardManager) ||
|   | ↳ | android.content.ClipboardManager |

<br />

*** ** * ** ***

Interface to the clipboard service, for placing and retrieving text in the global clipboard.

The ClipboardManager API itself is very simple: it consists of methods to atomically get and set the current primary clipboard data. That data is expressed as a[ClipData](https://developer.android.com/reference/android/content/ClipData)object, which defines the protocol for data exchange between applications.  

### Developer Guides

For more information about using the clipboard framework, read the[Copy and Paste](https://developer.android.com/guide/topics/clipboard/copy-paste)developer guide.

<br />

## Summary

|                                                                                                                        ### Nested classes                                                                                                                        ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [ClipboardManager.OnPrimaryClipChangedListener](https://developer.android.com/reference/android/content/ClipboardManager.OnPrimaryClipChangedListener) Defines a listener callback that is invoked when the primary clip on the clipboard changes. |

|                                                                                                                                                                                                                                                                                                        ### Public methods                                                                                                                                                                                                                                                                                                         ||
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                       | ` `[addPrimaryClipChangedListener](https://developer.android.com/reference/android/content/ClipboardManager#addPrimaryClipChangedListener(android.content.ClipboardManager.OnPrimaryClipChangedListener))`(`[ClipboardManager.OnPrimaryClipChangedListener](https://developer.android.com/reference/android/content/ClipboardManager.OnPrimaryClipChangedListener)` what) `                                                                                                                                                        |
| ` void`                                                                                       | ` `[clearPrimaryClip](https://developer.android.com/reference/android/content/ClipboardManager#clearPrimaryClip())`() ` Clears any current primary clip on the clipboard.                                                                                                                                                                                                                                                                                                                                                          |
| ` `[ClipData](https://developer.android.com/reference/android/content/ClipData)               | ` `[getPrimaryClip](https://developer.android.com/reference/android/content/ClipboardManager#getPrimaryClip())`() ` Returns the current primary clip on the clipboard.                                                                                                                                                                                                                                                                                                                                                             |
| ` `[ClipDescription](https://developer.android.com/reference/android/content/ClipDescription) | ` `[getPrimaryClipDescription](https://developer.android.com/reference/android/content/ClipboardManager#getPrimaryClipDescription())`() ` Returns a description of the current primary clip on the clipboard but not a copy of its data.                                                                                                                                                                                                                                                                                           |
| ` `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)             | ` `[getText](https://developer.android.com/reference/android/content/ClipboardManager#getText())`() ` *This method is deprecated. Use[getPrimaryClip()](https://developer.android.com/reference/android/content/ClipboardManager#getPrimaryClip())instead. This retrieves the primary clip and tries to coerce it to a string.*                                                                                                                                                                                                    |
| ` boolean`                                                                                    | ` `[hasPrimaryClip](https://developer.android.com/reference/android/content/ClipboardManager#hasPrimaryClip())`() ` Returns true if there is currently a primary clip on the clipboard.                                                                                                                                                                                                                                                                                                                                            |
| ` boolean`                                                                                    | ` `[hasText](https://developer.android.com/reference/android/content/ClipboardManager#hasText())`() ` *This method is deprecated. Use[hasPrimaryClip()](https://developer.android.com/reference/android/content/ClipboardManager#hasPrimaryClip())instead.*                                                                                                                                                                                                                                                                        |
| ` void`                                                                                       | ` `[removePrimaryClipChangedListener](https://developer.android.com/reference/android/content/ClipboardManager#removePrimaryClipChangedListener(android.content.ClipboardManager.OnPrimaryClipChangedListener))`(`[ClipboardManager.OnPrimaryClipChangedListener](https://developer.android.com/reference/android/content/ClipboardManager.OnPrimaryClipChangedListener)` what) `                                                                                                                                                  |
| ` void`                                                                                       | ` `[setPrimaryClip](https://developer.android.com/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData))`(`[ClipData](https://developer.android.com/reference/android/content/ClipData)` clip) ` Sets the current primary clip on the clipboard.                                                                                                                                                                                                                                                     |
| ` void`                                                                                       | ` `[setText](https://developer.android.com/reference/android/content/ClipboardManager#setText(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text) ` *This method is deprecated. Use[setPrimaryClip(android.content.ClipData)](https://developer.android.com/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData))instead. This creates a ClippedItem holding the given text and sets it as the primary clip. It has no label or icon.* |

| ### Inherited methods |
|-----------------------|---|
| From class` `[android.text.ClipboardManager](https://developer.android.com/reference/android/text/ClipboardManager)` ` |--------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[getText](https://developer.android.com/reference/android/text/ClipboardManager#getText())`() ` Returns the text on the clipboard.                                                                                                                                   | | ` abstract boolean`                                                                        | ` `[hasText](https://developer.android.com/reference/android/text/ClipboardManager#hasText())`() ` Returns true if the clipboard contains text; false otherwise.                                                                                                        | | ` abstract void`                                                                           | ` `[setText](https://developer.android.com/reference/android/text/ClipboardManager#setText(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text) ` Sets the contents of the clipboard to the specified text. | ||
| 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*.                                                                                             | ||

## Public methods

### addPrimaryClipChangedListener

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

```
public void addPrimaryClipChangedListener (ClipboardManager.OnPrimaryClipChangedListener what)
```

<br />

<br />

|                           Parameters                           ||
|--------|--------------------------------------------------------|
| `what` | `ClipboardManager.OnPrimaryClipChangedListener` <br /> |

### clearPrimaryClip

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

```
public void clearPrimaryClip ()
```

Clears any current primary clip on the clipboard.

<br />

**See also:**

- [setPrimaryClip(ClipData)](https://developer.android.com/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData))  

### getPrimaryClip

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

```
public ClipData getPrimaryClip ()
```

Returns the current primary clip on the clipboard.*If the application is not the default IME or does not have input focus this return`null`.*

<br />

|                                       Returns                                        ||
|------------------------------------------------------------------------------|--------|
| [ClipData](https://developer.android.com/reference/android/content/ClipData) | <br /> |

**See also:**

- [setPrimaryClip(ClipData)](https://developer.android.com/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData))  

### getPrimaryClipDescription

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

```
public ClipDescription getPrimaryClipDescription ()
```

Returns a description of the current primary clip on the clipboard but not a copy of its data.

*If the application is not the default IME or does not have input focus this return`null`.*

<br />

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| [ClipDescription](https://developer.android.com/reference/android/content/ClipDescription) | <br /> |

**See also:**

- [setPrimaryClip(ClipData)](https://developer.android.com/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData))  

### getText

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

```
public CharSequence getText ()
```

<br />

**This method is deprecated.**   
Use[getPrimaryClip()](https://developer.android.com/reference/android/content/ClipboardManager#getPrimaryClip())instead. This retrieves the primary clip and tries to coerce it to a string.

Returns the text on the clipboard. It will eventually be possible to store types other than text too, in which case this will return null if the type cannot be coerced to text.

<br />

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### hasPrimaryClip

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

```
public boolean hasPrimaryClip ()
```

Returns true if there is currently a primary clip on the clipboard.*If the application is not the default IME or the does not have input focus this will return`false`.*

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### hasText

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

```
public boolean hasText ()
```

<br />

**This method is deprecated.**   
Use[hasPrimaryClip()](https://developer.android.com/reference/android/content/ClipboardManager#hasPrimaryClip())instead.

Returns true if the clipboard contains text; false otherwise.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### removePrimaryClipChangedListener

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

```
public void removePrimaryClipChangedListener (ClipboardManager.OnPrimaryClipChangedListener what)
```

<br />

<br />

|                           Parameters                           ||
|--------|--------------------------------------------------------|
| `what` | `ClipboardManager.OnPrimaryClipChangedListener` <br /> |

### setPrimaryClip

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

```
public void setPrimaryClip (ClipData clip)
```

Sets the current primary clip on the clipboard. This is the clip that is involved in normal cut and paste operations.

<br />

|                                      Parameters                                      ||
|--------|------------------------------------------------------------------------------|
| `clip` | `ClipData`: The clipped data item to set. This value cannot be`null`. <br /> |

**See also:**

- [getPrimaryClip()](https://developer.android.com/reference/android/content/ClipboardManager#getPrimaryClip())
- [clearPrimaryClip()](https://developer.android.com/reference/android/content/ClipboardManager#clearPrimaryClip())  

### setText

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

```
public void setText (CharSequence text)
```

<br />

**This method is deprecated.**   
Use[setPrimaryClip(android.content.ClipData)](https://developer.android.com/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData))instead. This creates a ClippedItem holding the given text and sets it as the primary clip. It has no label or icon.

Sets the contents of the clipboard to the specified text.

<br />

|          Parameters           ||
|--------|-----------------------|
| `text` | `CharSequence` <br /> |