2

Is it possible to capture the text that is rendered on screen from any app using an app or adb, for the purposes of automated testing, or accessibility?

My only alternative is to take a screenshot and run it through an OCR application.

Matt Copperwaite
  • 280
  • 4
  • 10
  • Do you control the application that is printing the text? If no, what kind of text are you trying to get, generated by what application, etc? – jconder Sep 26 '16 at 15:20
  • 1
    see if http://stackoverflow.com/q/26586685/1778421 would work for you – Alex P. Sep 26 '16 at 15:36
  • @AlexP. that looks like it does work, but looks like it applies to your own apps, or to all apps? – Matt Copperwaite Sep 26 '16 at 15:43
  • @jconder I don't control the application. Let's say I want to get to the folder name in Gmail, such as 'Inbox'. – Matt Copperwaite Sep 26 '16 at 15:45
  • 1
    It works for all normal apps (ones using regular widgets with accessibility support). The apps do not have to be the debug versions – Alex P. Sep 26 '16 at 15:47

1 Answers1

3

for the purposes of automated testing

If this is your UI, write instrumentation tests using Espresso, which has result matchers for checking the text of TextView and its subclasses.

If this is not your UI, and you are performing integration testing, write instrumentation tests using UI Automator, which has some ability to get text from TextView and its subclasses.

for the purposes of... accessibility

Write an AccessibilityService.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491