I have used a solution from the SO accepted answer here.
It works well inside an Activity but when I implement it inside a Fragment, I got the following error:
Exception thrown from receiver.java.lang.ClassCastException: com.example.app.MainActivity cannot be cast to com.example.app.QRCodeDetectedInterface at com.example.app.BarcodeGraphic.(OcrGraphic.java:54) at com.example.app.OcrDetectorProcessor.receiveDetections(OcrDetectorProcessor.java:49)
It seems there is a problem implementing the interface inside the Fragment. How to overcome this error?
In link you provided BarcodeCaptureActivity listens to events. In your case, as exception suggests, MainActivity listens to events. Your com.example.app.MainActivity must implement com.example.app.QRCodeDetectedInterface.