Juni
Juni

Reputation: 737

Get text content on Android screen – even if it is not visible

It is possible to get the text content of an Android screen by creating an Accessibility Service. This method is restricted to content that is currently visible on screen.

Is it also possible to get the text of views that are not currently visible on screen, for example that the user would have to scroll to see?

For example, I could get the text of the first comment on this HN post with the Accessibility Service, but how can I get the text of the second comment?

enter image description here

Upvotes: 0

Views: 726

Answers (1)

Juni
Juni

Reputation: 737

It seems like this depends on the type of view used in the App which you want to read the text from.

It turns out if you open this website in the Chrome App, you can access the text content of the entire page. But if you open it in Firefox, you can only access as much as is currently visible on screen.

Inspecting the view hierarchy of some WebViews (as used in Chrome) with UI Automator Viewer, it seems like their content can be accessed completely, even when it is not completely visible.

On the other hand, content in RecyclerViews for example only gets rendered when necessary. Thus it can only be accessed when it is actually visible. For ListViews, this is not always the case. For example, in the dict.cc App, the text content in all items of the ListViews can be accessed.

Thus, if you want to to read the text content of the entire window, you have to be lucky that the text view is not optimized away from the view hierarchy.

Upvotes: 0

Related Questions