Search code examples
androidresponse

How can I fix response text?


I use Google Cloud Vision Api (Text_Detection) it is working normal but when I return answer from the Google, message style like image

I want just one text e.g "ACADEMIC PLANNER" so how can I remove front of Academic "null:" and other words?

Image e.g

enter image description here

And here is my code;

private String convertResponseToString(BatchAnnotateImagesResponse response) {
    String message = "I found these things:\n\n";

    List<EntityAnnotation> labels = response.getResponses().get(0).getTextAnnotations();
    if (labels != null) {
        for (EntityAnnotation label : labels) {
            message += String.format("%.3f: %s", label.getScore(), label.getDescription());
            message += "\n";
        }
    } else {
        message += "nothing";
    }

    return message;
}

Solution

  • Answer:

    private String convertResponseToString(BatchAnnotateImagesResponse response) {
        String message = "I found these things:\n\n";
        List<EntityAnnotation> labels = response.getResponses().get(0).getTextAnnotations();
        if (labels != null) {
          message += labels.get(0).getDescription();
        } else {
          message += "nothing";
        }
        return message;
    }