android / codelab-android-accessibility

Basic Android Accessibility: making sure everyone can use what you create!
https://codelabs.developers.google.com/codelabs/basic-android-accessibility/
Apache License 2.0
112 stars 86 forks source link

getRootInActiveWindow returns null even though android:canRetrieveWindowContent="true" #27

Open levis501 opened 4 years ago

levis501 commented 4 years ago

Following the Scroll button portion of the sample, the service crashes whenever the scroll button is pressed. The getRootInActiveWindow() call is returning null even though, according to the API, this should not happen when android:canRetrieveWindowContent="true", which it is in both the github repository and in my own working directory.

levis501 commented 4 years ago

I found a solution, by caching the root node from received events

AccessibilityNodeInfo mLastKnownRoot; @Override public void onAccessibilityEvent(AccessibilityEvent event) { AccessibilityNodeInfo root = event.getSource(); while (root != null) { mLastKnownRoot = root; root = root.getParent(); } }

The mLastKnownRoot can be used as the argument to findScrollableNode when getRootInActiveWindow is null. Also, the permission android:accessibilityEventTypes="typeAllMask" should be added to the accessibility-service xml

Angelo198221 commented 2 years ago

Hola

Angelo198221 commented 2 years ago

Hola

mkumar7404508129 commented 1 year ago

I have same problem. It giving null vlaue