# TransferableContent

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/content/TransferableContent.kt+class:androidx.compose.foundation.content.TransferableContent) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0) Common/AllAndroid/JVM
- Cmn

  ```
  @ExperimentalFoundationApi
  class TransferableContent
  ```

*** ** * ** ***

Represents content that can be transferred between applications or processes.

Note; Consult platform-specific guidelines for best practices in content transfer operations.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi value class https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.Source` Defines the type of operation that a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` originates from. |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ClipEntry` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent#clipEntry()` The main content data, typically representing a text, image, file, or other transferable item. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ClipMetadata` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent#clipMetadata()` Metadata associated with the content, providing additional information or context. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/PlatformTransferableContent?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent#platformTransferableContent()` Optional platform-specific representation of the content, or additional platform-specific information, that can be used to access platform level APIs. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.Source` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent#source()` The source from which the content originated like Keyboard, DragAndDrop, or Clipboard. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent?` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent#(androidx.compose.foundation.content.TransferableContent).consume(kotlin.Function1)(predicate: (https://developer.android.com/reference/android/content/ClipData.Item.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Helper function to consume parts of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` in Android by splitting it to `https://developer.android.com/reference/android/content/ClipData.Item.html` parts. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent#(androidx.compose.foundation.content.TransferableContent).hasMediaType(androidx.compose.foundation.content.MediaType)(mediaType: https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/MediaType)` Returns whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` can provide an item with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/package-summary#(androidx.compose.foundation.content.TransferableContent).hasMediaType(androidx.compose.foundation.content.MediaType)`. | Cmn android |

## Public properties

### clipEntry

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
val clipEntry: ClipEntry
```

The main content data, typically representing a text, image, file, or other transferable item.

### clipMetadata

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
val clipMetadata: ClipMetadata
```

Metadata associated with the content, providing additional information or context.

### platformTransferableContent

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
val platformTransferableContent: PlatformTransferableContent?
```

Optional platform-specific representation of the content, or additional platform-specific information, that can be used to access platform level APIs.

### source

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
val source: TransferableContent.Source
```

The source from which the content originated like Keyboard, DragAndDrop, or Clipboard.

## Extension functions

### TransferableContent.consume

android Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/content/TransferableContent.android.kt+function:consume)

```
@ExperimentalFoundationApi
fun TransferableContent.consume(predicate: (ClipData.Item) -> Boolean): TransferableContent?
```

Helper function to consume parts of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` in Android by splitting it to `https://developer.android.com/reference/android/content/ClipData.Item.html` parts. Use this function in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/contentReceiver.modifier#(androidx.compose.ui.Modifier).contentReceiver(androidx.compose.foundation.content.ReceiveContentListener)` modifier's `onReceive` callback to easily separate remaining parts from incoming `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`.

```kotlin
import androidx.compose.foundation.Image
import androidx.compose.foundation.content.MediaType
import androidx.compose.foundation.content.consume
import androidx.compose.foundation.content.contentReceiver
import androidx.compose.foundation.content.hasMediaType
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap

val state = rememberTextFieldState()
var images by remember { mutableStateOf<List<ImageBitmap>>(emptyList()) }
Column {
    Row { images.forEach { Image(bitmap = it, contentDescription = null) } }
    BasicTextField(
        state = state,
        modifier =
            Modifier.contentReceiver { transferableContent ->
                if (!transferableContent.hasMediaType(MediaType.Image)) {
                    return@contentReceiver transferableContent
                }
                val newImages = mutableListOf<ImageBitmap>()
                transferableContent
                    .consume { item ->
                        // only consume this item if we can read an imageBitmap
                        item.readImageBitmap()?.let {
                            newImages += it
                            true
                        } ?: false
                    }
                    .also { images = newImages }
            },
    )
}
```

| Parameters |
|---|---|
| `predicate: (https://developer.android.com/reference/android/content/ClipData.Item.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Decides whether to consume or leave the given item out. Return true to indicate that this particular item was processed here, it shouldn't be passed further down the content receiver chain. Return false to keep it in the returned `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent?` | Remaining parts of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`. |

### TransferableContent.hasMediaType

Cmn android Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/content/TransferableContent.+function:hasMediaType)

```
@ExperimentalFoundationApi
fun TransferableContent.hasMediaType(mediaType: MediaType): Boolean
```

Returns whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` can provide an item with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/package-summary#(androidx.compose.foundation.content.TransferableContent).hasMediaType(androidx.compose.foundation.content.MediaType)`.