i want to Scroll the current screen.
i tried this
AccessibilityNodeInfo accessibilityNodeInfo=getRootInActiveWindow();
accessibilityNodeInfo.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN);
but i always say "Cannot perform this action on a sealed instance".
help please.
First: The problem with what you're trying to do.
When you see this
Cannot perform this action on a sealed instance.
This message is Android telling you that the information you have is set. Does it make sense for you to be able to tell a view, that is not scrollable, that it is? NO. You CAN NOT force a view to be scrollable. A view being scrollable is up to the view. For example, a Button being scrollable makes no sense! An accessibility service can't force this behavior.
It is very likely that the root node of an application is some type of frame layout, and will never be scrollable. The scrollable portion of the hierarchy is almost always a child of the main layout/root view. Moral of the story, you can't tell a view to be scrollable, you must find a scrollable view.
This being said, I'm going to give you a much better solution for this, hopefully it is within the range of devices that you support.
@TargetApi(Build.VERSION_CODES.M)
public boolean scrollTo(AccessibilityNodeInfo nodeInfo) {
return nodeInfo.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SHOW_ON_SCREEN.getId());
}
If you need to support versions befor Android M, what you need to do is explore the AccessibilityNodeInfo Hierarchy for the view within the layout where this is true, this would look approximate like this (Not tested, but should be very close!):
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;
}