# 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)

*** ** * ** ***


```
public class ContentCaptureSessionCompat
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/autofill/AutofillId.html` | `https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#newAutofillId(long)(long virtualChildId)` 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://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/view/ViewStructureCompat` | `https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#newVirtualViewStructure(android.view.autofill.AutofillId,long)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/autofill/AutofillId.html parentId, long virtualId)` 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/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsAppeared(java.util.List<android.view.ViewStructure>)` by the view managing the virtual view hierarchy. |
| `void` | `https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewTextChanged(android.view.autofill.AutofillId,java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/autofill/AutofillId.html id, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html text)` Notifies the Intelligence Service that the value of a text node has been changed. |
| `void` | `https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsAppeared(java.util.List<android.view.ViewStructure>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/view/ViewStructure.html> appearedNodes)` Notifies the Content Capture Service that a list of nodes has appeared in the view structure. |
| `void` | `https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#notifyViewsDisappeared(long[])(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html long[] virtualIds)` Notifies the Content Capture Service that many nodes has been removed from a virtual view structure. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#toContentCaptureSession()()` Provides the `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` represented by this object. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat#toContentCaptureSessionCompat(android.view.contentcapture.ContentCaptureSession,android.view.View)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html contentCaptureSession, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host )` Provides a backward-compatible wrapper for `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html`. |

## Public methods

### newAutofillId

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

```
public @Nullable AutofillId newAutofillId(long virtualChildId)
```

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 |
|---|---|
| `long virtualChildId` | id of the virtual child, relative to the parent. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html 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)

```
public @Nullable ViewStructureCompat newVirtualViewStructure(@NonNull AutofillId parentId, long virtualId)
```

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/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/autofill/AutofillId.html parentId` | 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). |
| `long virtualId` | id of the virtual child, relative to the parent. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/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)

```
public void notifyViewTextChanged(@NonNull AutofillId id, @Nullable CharSequence text)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/autofill/AutofillId.html id` | of the node. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html text` | new text. |

### notifyViewsAppeared

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

```
public void notifyViewsAppeared(@NonNull List<ViewStructure> appearedNodes)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/view/ViewStructure.html> appearedNodes` | 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)

```
public void notifyViewsDisappeared(@NonNull long[] virtualIds)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html long[] virtualIds` | 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)
public @NonNull ContentCaptureSession toContentCaptureSession()
```

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://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html` | platform class object |

| See also |
|---|---|
| `https://developer.android.com/reference/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)
public static @NonNull ContentCaptureSessionCompat toContentCaptureSessionCompat(
    @NonNull ContentCaptureSession contentCaptureSession,
    @NonNull View host
)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html contentCaptureSession` | platform class to wrap |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host` | view hosting the session. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/contentcapture/ContentCaptureSessionCompat` | wrapped class |