0
var text:String = ""
var result = TextRecognition.getClient().process(image)
    .addOnSuccessListener { visionText ->
    text = visionText.text
    Log.d("OUTPUT",visionText.text)
    }
findViewById<TextView>(R.id.txt_Original).setText("ORIGNAL: "+text);

I'm giving the text recognition an image to read text from. I then want to assign that text to my variable "text". However, the text from the image isn't being assigned to my variable. I added a Log.d to see if anything is being read and the text from the photo is being read as it returns the correct text from the image.

  • I added the "ORIGNAL" to the setText just to make sure it isn't just skipping that line, and it is setting the text to "ORIGNAL: " but no text. But I know Its getting to that point
  • If I assign the TextView directly inside the addOnSucessListener, then it works. However, I need to do things to the text so I would like to keep it as a variable
Marnie Rodriguez
  • 431
  • 2
  • 8
  • 22

1 Answers1

1

After adding a Log after the function call, I found out that the log afterwards was running first and then the log inside the function ran. I'm assuming the function is acting asynchronous. Thus I moved all the code I wanted to run (basically all of it) into the addOnSuccessListener. Its messy but it runs now!

Marnie Rodriguez
  • 431
  • 2
  • 8
  • 22