Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#constants) \| [Ctors](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#pubctors) \| [Methods](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#inhmethods)

# AccessibilityNodeProvider

*** ** * ** ***

` public abstract class AccessibilityNodeProvider `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.accessibility.AccessibilityNodeProvider |

<br />

*** ** * ** ***

This class is the contract a client should implement to enable support of a virtual view hierarchy rooted at a given view for accessibility purposes. A virtual view hierarchy is a tree of imaginary Views that is reported as a part of the view hierarchy when an `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService` explores the window content. Since the virtual View tree does not exist this class is responsible for managing the `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`s describing that tree to accessibility services.

The main use case of these APIs is to enable a custom view that draws complex content, for example a monthly calendar grid, to be presented as a tree of logical nodes, for example month days each containing events, thus conveying its logical structure.

<br />

A typical use case is to override `https://developer.android.com/reference/android/view/View#getAccessibilityNodeProvider()` of the View that is a root of a virtual View hierarchy to return an instance of this class. In such a case this instance is responsible for managing `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`s describing the virtual sub-tree rooted at the View including the one representing the View itself. Similarly the returned instance is responsible for performing accessibility actions on any virtual view or the root view itself. For example:

> [!NOTE]
> **Note:** Consider using a `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper.html`, a utility extension of AccessibilityNodeProvider, to simplify many aspects of providing information to accessibility services and managing accessibility focus.

### Kotlin

```kotlin
// "view" is the View instance on which this class performs accessibility functions.
class MyCalendarViewAccessibilityDelegate(
      private var view: MyCalendarView) : AccessibilityDelegate() {
    override fun getAccessibilityNodeProvider(host: View): AccessibilityNodeProvider {
        return object : AccessibilityNodeProvider() {
            override fun createAccessibilityNodeInfo(virtualViewId: Int):
                    AccessibilityNodeInfo? {
                when (virtualViewId) {
                    host-view-id -> {
                        val node = AccessibilityNodeInfo.obtain(view)
                        node.addChild(view, child-view-id)
                        // Set other attributes like screenReaderFocusable
                        // and contentDescription.
                        return node
                    }
                    child-view-id -> {
                        val node = AccessibilityNodeInfo
                                .obtain(view, virtualViewId)
                        node.setParent(view)
                        node.addAction(ACTION_SCROLL_UP)
                        node.addAction(ACTION_SCROLL_DOWN)
                        // Set other attributes like focusable and visibleToUser.
                        node.setBoundsInScreen(
                                Rect(coords-of-edges-relative-to-screen))
                        return node
                    }
                    else -> return null
                }
            }

            override fun performAction(
                virtualViewId: Int,
                action: Int,
                arguments: Bundle
            ): Boolean {
                if (virtualViewId == host-view-id) {
                    return view.performAccessibilityAction(action, arguments)
                }
                when (action) {
                    ACTION_SCROLL_UP.id -> {
                        // Implement logic in a separate method.
                        navigateToPreviousMonth()

                        return true
                    }
                    ACTION_SCROLL_DOWN.id ->
                        // Implement logic in a separate method.
                        navigateToNextMonth()

                        return true
                    else -> return false
                }
            }
        }
    }
}
```

### Java

```java
final class MyCalendarViewAccessibilityDelegate extends AccessibilityDelegate {
    // The View instance on which this class performs accessibility functions.
    private final MyCalendarView view;

    MyCalendarViewAccessibilityDelegate(MyCalendarView view) {
        this.view = view;
    }

    @Override
    public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) {
        return new AccessibilityNodeProvider() {
            @Override
            @Nullable
            public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
                if (virtualViewId == host-view-id) {
                    AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(view);
                    node.addChild(view, child-view-id);
                    // Set other attributes like screenReaderFocusable and contentDescription.
                    return node;
                } else if (virtualViewId == child-view-id) {
                    AccessibilityNodeInfo node =
                        AccessibilityNodeInfo.obtain(view, virtualViewId);
                    node.setParent(view);
                    node.addAction(ACTION_SCROLL_UP);
                    node.addAction(ACTION_SCROLL_DOWN);
                    // Set other attributes like focusable and visibleToUser.
                    node.setBoundsInScreen(
                        new Rect(coordinates-of-edges-relative-to-screen));
                    return node;
                } else {
                    return null;
                }
            }

            @Override
            public boolean performAction(int virtualViewId, int action, Bundle arguments) {
                if (virtualViewId == host-view-id) {
                    return view.performAccessibilityAction(action, arguments);
                }

                if (action == ACTION_SCROLL_UP.getId()) {
                    // Implement logic in a separate method.
                    navigateToPreviousMonth();

                    return true;
                } else if (action == ACTION_SCROLL_DOWN.getId()) {
                    // Implement logic in a separate method.
                    navigateToNextMonth();

                    return true;
                } else {
                    return false;
                }
            }
        };
    }
}
```

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#HOST_VIEW_ID` The virtual id for the hosting View. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#AccessibilityNodeProvider()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#addExtraDataToAccessibilityNodeInfo(int,%20android.view.accessibility.AccessibilityNodeInfo,%20java.lang.String,%20android.os.Bundle)(int virtualViewId, https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo info, https://developer.android.com/reference/java/lang/String extraDataKey, https://developer.android.com/reference/android/os/Bundle arguments) ` Adds extra data to an `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` based on an explicit request for the additional data. |
| ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` | ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#createAccessibilityNodeInfo(int)(int virtualViewId) ` Returns an `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` representing a virtual view, such as a descendant of the host View, with the given `virtualViewId` or the host View itself if `virtualViewId` equals to `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#HOST_VIEW_ID`. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo>` | ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#findAccessibilityNodeInfosByText(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String text, int virtualViewId) ` Finds `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`s by text. |
| ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` | ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#findFocus(int)(int focus) ` Find the virtual view, such as a descendant of the host View, that has the specified focus type. |
| ` boolean` | ` https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#performAction(int,%20int,%20android.os.Bundle)(int virtualViewId, int action, https://developer.android.com/reference/android/os/Bundle arguments) ` Performs an accessibility action on a virtual view, such as a descendant of the host View, with the given `virtualViewId` or the host View itself if `virtualViewId` equals to `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#HOST_VIEW_ID`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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*.

## Constants

### HOST_VIEW_ID

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

```
public static final int HOST_VIEW_ID
```

The virtual id for the hosting View.

<br />

Constant Value: -1 (0xffffffff)

## Public constructors

### AccessibilityNodeProvider

```
public AccessibilityNodeProvider ()
```

<br />

<br />

## Public methods

### addExtraDataToAccessibilityNodeInfo

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

```
public void addExtraDataToAccessibilityNodeInfo (int virtualViewId, 
                AccessibilityNodeInfo info, 
                String extraDataKey, 
                Bundle arguments)
```

Adds extra data to an `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` based on an explicit request for the additional data.

This method only needs to be implemented if a virtual view offers to provide additional data.

<br />

<br />

| Parameters ||
|---|---|
| `virtualViewId` | `int`: The virtual view id used to create the node <br /> |
| `info` | `AccessibilityNodeInfo`: The info to which to add the extra data <br /> |
| `extraDataKey` | `String`: A key specifying the type of extra data to add to the info. The extra data should be added to the `https://developer.android.com/reference/android/os/Bundle` returned by the info's `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#getExtras()` method. <br /> |
| `arguments` | `Bundle`: A `https://developer.android.com/reference/android/os/Bundle` holding any arguments relevant for this request. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#setAvailableExtraData(java.util.List<java.lang.String>)`

### createAccessibilityNodeInfo

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

```
public AccessibilityNodeInfo createAccessibilityNodeInfo (int virtualViewId)
```

Returns an `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` representing a virtual view, such as a descendant of the host View, with the given `virtualViewId` or the host View itself if `virtualViewId` equals to `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#HOST_VIEW_ID`.

A virtual descendant is an imaginary View that is reported as a part of the view hierarchy for accessibility purposes. This enables custom views that draw complex content to report them selves as a tree of virtual views, thus conveying their logical structure.

The implementer is responsible for obtaining an accessibility node info from the pool of reusable instances and setting the desired properties of the node info before returning it.

<br />

<br />

| Parameters ||
|---|---|
| `virtualViewId` | `int`: A client defined virtual view id. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` | A populated `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` for a virtual descendant or the host View. This value may be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#createAccessibilityNodeInfo()`
- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`

### findAccessibilityNodeInfosByText

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

```
public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText (String text, 
                int virtualViewId)
```

Finds `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`s by text. The match is case insensitive containment. The search is relative to the virtual view, i.e. a descendant of the host View, with the given `virtualViewId` or the host View itself `virtualViewId` equals to `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#HOST_VIEW_ID`.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The searched text. <br /> |
| `virtualViewId` | `int`: A client defined virtual view id which defined the root of the tree in which to perform the search. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo>` | A list of node info. This value may be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#createAccessibilityNodeInfo(int)`
- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`

### findFocus

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

```
public AccessibilityNodeInfo findFocus (int focus)
```

Find the virtual view, such as a descendant of the host View, that has the specified focus type.

<br />

| Parameters ||
|---|---|
| `focus` | `int`: The focus to find. One of `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#FOCUS_INPUT` or `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#FOCUS_ACCESSIBILITY`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo` | The node info of the focused view or null. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#FOCUS_INPUT`
- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#FOCUS_ACCESSIBILITY`

### performAction

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

```
public boolean performAction (int virtualViewId, 
                int action, 
                Bundle arguments)
```

Performs an accessibility action on a virtual view, such as a descendant of the host View, with the given `virtualViewId` or the host View itself if `virtualViewId` equals to `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#HOST_VIEW_ID`.

<br />

| Parameters ||
|---|---|
| `virtualViewId` | `int`: A client defined virtual view id. <br /> |
| `action` | `int`: The action to perform. <br /> |
| `arguments` | `Bundle`: Optional action arguments. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | True if the action was performed. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#performAccessibilityAction(int,%20android.os.Bundle)`
- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider#createAccessibilityNodeInfo(int)`
- `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo`