Show a toast message when a text is recognized from camera

Viewed 1115

I am trying to detect a text with a specific format from a live camera feed and show a toast message when that text is detected automatically. I was able to detect the text and put a box around it. But I'm having a hard time showing that toast message.

This is the receiveDetections method from the Processor

@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    mGraphicOverlay.clear();
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);
        if (item != null && item.getValue() != null) {
            Log.d("OcrDetectorProcessor", "Text detected! " + item.getValue());

            // Check if it is the correct format
            if (item.getValue().matches("^\\d{3} \\d{3} \\d{4} \\d{4}")){
                OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
                mGraphicOverlay.add(graphic);

                // Show the toast message

            }
        }


    }
}

-> Showing a toast is not my end goal, If I'm able to fix that I'll fix the main problem. -> I'm building on top of the code labs tutorial for the text vision api

1 Answers
Related