3

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.

Ali Asjad
  • 253
  • 1
  • 4
  • 11

1 Answers1

1

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

MobA11y
  • 18,425
  • 3
  • 49
  • 76
  • But bro when i call method performAction on AccessibilityNodeInfo and pass action of AccessibilityNodeInfo.AccessibilityAction it gives error that you can not perform action on node from AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN it only let perform AccessibilityNodeInfo.ACTION_SCROLL_FORWARD or AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD. – Ali Asjad Jun 19 '17 at 06:15
  • Then you either A: Have the wrong scrollable node (there can be more than 1), or B: you're hosed and have to use the accessibility gestures API, which is more complicated, but less dependent on Android getting things right. – MobA11y Jun 19 '17 at 13:31
  • can you give a simple example please? – Ali Asjad Jun 19 '17 at 13:34
  • https://stackoverflow.com/questions/44420320/perform-swipe-on-screen-using-accessibilityservice/44448362#44448362 – MobA11y Jun 19 '17 at 13:36
  • i don't know but it was not working in facebook app :( so i decided to switch on AccessibilityNodeInfo to perfrom scroll and you provided a great solution always ...but now i am just facing a problem that i told in question ..there is also an app that perform scroll on facebook app also using AccessibilityNodeInfo but i dont know how i also used getfocous() method and performed action on that but nothing. – Ali Asjad Jun 19 '17 at 13:42
  • If you're using the gestures API there's nothing keeping it from working beyond mis-use and API version (and potential platform bugs, but that API is pretty solid in my experience). None of your questions have enough information to pinpoint your issue. Everything in them is correct, meaning the issue is elsewhere. Most likely in the specific "AccessibilityNodeInfo" you've grabbed onto to "scroll". – MobA11y Jun 19 '17 at 13:45
  • there was also another problem using this gesture api that was when we perform gesture using that it also perform click on ending point....that we can see clearly so if there is a button on ending point it was clicking that button . – Ali Asjad Jun 19 '17 at 13:47
  • That's not a problem with the "gesture api" that's a problem with your use of the gesture API. – MobA11y Jun 19 '17 at 13:48
  • i am grabing that node from accessibility event by using method event.getsource() that return nodeinfo . – Ali Asjad Jun 19 '17 at 13:49
  • That's not necessarily correct EX: which event type, what has triggered this event, etc. You should look at the view hierarchy and see what elements are scrollable, this discussion is becoming too long, if you have questions you should post them, or perhaps since this one isn't really answered yet, add more detail. (Like the nodeInfo.toString() of the node that your scrolling, or event that you're grabbing the node from). – MobA11y Jun 19 '17 at 13:51
  • i edit this question and post all my code can you look into it? – Ali Asjad Jun 19 '17 at 13:53
  • At some point this becomes a consulting relationship and not a stack overflow answer. Perhaps you should reach out to me via email... PM me and I'll give you my email address. – MobA11y Jun 19 '17 at 13:55
  • where i pm you bro ? – Ali Asjad Jun 20 '17 at 08:54