# ContentCaptureSessionCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/contentcapture/ContentCaptureSessionCompat.java+class:androidx.core.view.contentcapture.ContentCaptureSessionCompat) Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

*** ** * ** ***

<br />

```
class ContentCaptureSessionCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html`.

## Summary

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/android/view/autofill/AutofillId.html?` | `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#newAutofillId(long)(virtualChildId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Creates a new `https://developer.android.com/reference/android/view/autofill/AutofillId.html` for a virtual child, so it can be used to uniquely identify the children in the session. |
| `https://developer.android.com/reference/kotlin/androidx/core/view/ViewStructureCompat?` | `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#newVirtualViewStructure(android.view.autofill.AutofillId,long)(parentId: https://developer.android.com/reference/android/view/autofill/AutofillId.html, virtualId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Creates a `https://developer.android.com/reference/android/view/ViewStructure.html` for a "virtual" view, so it can be passed to `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsAppeared(java.util.List<android.view.ViewStructure>)` by the view managing the virtual view hierarchy. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewTextChanged(android.view.autofill.AutofillId,java.lang.CharSequence)(id: https://developer.android.com/reference/android/view/autofill/AutofillId.html, text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?)` Notifies the Intelligence Service that the value of a text node has been changed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsAppeared(java.util.List<android.view.ViewStructure>)(appearedNodes: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/view/ViewStructure.html!>)` Notifies the Content Capture Service that a list of nodes has appeared in the view structure. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsDisappeared(long[])(virtualIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>)` Notifies the Content Capture Service that many nodes has been removed from a virtual view structure. |
| `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#toContentCaptureSession()()` Provides the `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` represented by this object. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#toContentCaptureSessionCompat(android.view.contentcapture.ContentCaptureSession,android.view.View)( contentCaptureSession: https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html, host: https://developer.android.com/reference/android/view/View.html )` Provides a backward-compatible wrapper for `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html`. |

## Public functions

### newAutofillId

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
fun newAutofillId(virtualChildId: Long): AutofillId?
```

Creates a new `https://developer.android.com/reference/android/view/autofill/AutofillId.html` for a virtual child, so it can be used to uniquely identify the children in the session. Compatibility behavior:

- SDK 29 and above, this method matches platform behavior.
- SDK 28 and below, this method returns null.

| Parameters |
|---|---|
| `virtualChildId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | id of the virtual child, relative to the parent. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/view/autofill/AutofillId.html?` | `https://developer.android.com/reference/android/view/autofill/AutofillId.html` for the virtual child |

### newVirtualViewStructure

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
fun newVirtualViewStructure(parentId: AutofillId, virtualId: Long): ViewStructureCompat?
```

Creates a `https://developer.android.com/reference/android/view/ViewStructure.html` for a "virtual" view, so it can be passed to `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsAppeared(java.util.List<android.view.ViewStructure>)` by the view managing the virtual view hierarchy. Compatibility behavior:

- SDK 29 and above, this method matches platform behavior.
- SDK 28 and below, this method returns null.

| Parameters |
|---|---|
| `parentId: https://developer.android.com/reference/android/view/autofill/AutofillId.html` | id of the virtual view parent (it can be obtained by calling `https://developer.android.com/reference/android/view/ViewStructure.html#getAutofillId()` on the parent). |
| `virtualId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | id of the virtual child, relative to the parent. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/ViewStructureCompat?` | a new `https://developer.android.com/reference/android/view/ViewStructure.html` that can be used for Content Capture purposes. |

### notifyViewTextChanged

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
fun notifyViewTextChanged(id: AutofillId, text: CharSequence?): Unit
```

Notifies the Intelligence Service that the value of a text node has been changed. Compatibility behavior:

- SDK 29 and above, this method matches platform behavior.
- SDK 28 and below, this method does nothing.

| Parameters |
|---|---|
| `id: https://developer.android.com/reference/android/view/autofill/AutofillId.html` | of the node. |
| `text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` | new text. |

### notifyViewsAppeared

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
fun notifyViewsAppeared(appearedNodes: (Mutable)List<ViewStructure!>): Unit
```

Notifies the Content Capture Service that a list of nodes has appeared in the view structure.

Typically called manually by views that handle their own virtual view hierarchy. Compatibility behavior:

- SDK 34 and above, this method matches platform behavior.
- SDK 29 through 33, this method is a best-effort to match platform behavior, by wrapping the virtual children with a pair of special view appeared events.
- SDK 28 and below, this method does nothing.

| Parameters |
|---|---|
| `appearedNodes: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/view/ViewStructure.html!>` | nodes that have appeared. Each element represents a view node that has been added to the view structure. The order of the elements is important, which should be preserved as the attached order of when the node is attached to the virtual view hierarchy. |

### notifyViewsDisappeared

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
fun notifyViewsDisappeared(virtualIds: LongArray<Long>): Unit
```

Notifies the Content Capture Service that many nodes has been removed from a virtual view structure.

Should only be called by views that handle their own virtual view hierarchy. Compatibility behavior:

- SDK 34 and above, this method matches platform behavior.
- SDK 29 through 33, this method is a best-effort to match platform behavior, by wrapping the virtual children with a pair of special view appeared events.
- SDK 28 and below, this method does nothing.

| Parameters |
|---|---|
| `virtualIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>` | ids of the virtual children. |

### toContentCaptureSession

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
@RequiresApi(value = 29)
fun toContentCaptureSession(): ContentCaptureSession
```

Provides the `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` represented by this object.

This method is not supported on devices running SDK \<29 since the platform class will not be available.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` | platform class object |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat#toContentCaptureSessionCompat(android.view.contentcapture.ContentCaptureSession,android.view.View)` |   |

### toContentCaptureSessionCompat

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
@RequiresApi(value = 29)
java-static fun toContentCaptureSessionCompat(
    contentCaptureSession: ContentCaptureSession,
    host: View
): ContentCaptureSessionCompat
```

Provides a backward-compatible wrapper for `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html`.

This method is not supported on devices running SDK \<29 since the platform class will not be available.

| Parameters |
|---|---|
| `contentCaptureSession: https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` | platform class to wrap |
| `host: https://developer.android.com/reference/android/view/View.html` | view hosting the session. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/contentcapture/ContentCaptureSessionCompat` | wrapped class |