Ali Asjad
Ali Asjad

Reputation: 253

Scroll up and scroll down using AccessibilityNodeInfo in Accessibility Service

I want to perform scroll using Accessibility service and i am doing this

public boolean scrollView(AccessibilityNodeInfo nodeInfo) {

if (nodeInfo == null) return false;

if (nodeInfo.isScrollable()) {
    return nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}

for (int i = 0; i < nodeInfo.getChildCount(); i++) {
    if (scrollView(nodeInfo.getChild(i)) {
        return true;
    }
}

return false; }

But problem is when there are four option to perform up,down left and right it performs left and right but i want to perform up and down there also. like in facebook app it scroll on top section where notifications and news feed are.But not on page. is there any way to scroll where is focus of user.

Upvotes: 3

Views: 6676

Answers (1)

MobA11y
MobA11y

Reputation: 18870

You're probably scrolling the wrong container. There are likely multiple views in your heirarchy that are "scrollable". Try finding different scrollable views within your heirarchy.

Also, in Android M they added APIs to do things like specifically scroll different directions. So, if you are in fact on the correct View, you can scroll in different directions using these actions instead:

ACTION_SCROLL_FORWARD
ACTION_SCROLL_LEFT
ACTION_SCROLL_RIGHT

etc.

https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.AccessibilityAction.html

Upvotes: 1

Related Questions