codelab-android-accessibility icon indicating copy to clipboard operation
codelab-android-accessibility copied to clipboard

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

Open levis501 opened this issue 5 years ago • 4 comments

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 avatar Apr 30 '20 00:04 levis501

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

levis501 avatar Apr 30 '20 02:04 levis501

Hola

Angelo198221 avatar Aug 30 '22 06:08 Angelo198221

Hola

Angelo198221 avatar Aug 30 '22 06:08 Angelo198221

I have same problem. It giving null vlaue

mkumar7404508129 avatar Dec 26 '22 09:12 mkumar7404508129