androidstreamcameraandroid-activitylive

Embedding camera into activity (live stream)


I'm currently looking into ways to embed a live photo/video stream from the camera into an activity of my application. Ideally there would be some sort of ImageView that would directly display the stream coming in from the camera. By tapping on this view the usual camera activity might be started. The final goal is to recognize QR codes within this ImageView, which might make things even more complicated.

All of this can be done pretty easy by using the ZXing library, but I don't see a way to combine this in the way described above. Would this even be possible? Can you give me some hints towards what I should take a more detailed look at?

Wireframe


Solution

  • Ideally there would be some sort of ImageView that would directly display the stream coming in from the camera.

    This is called the camera preview, and it usually uses a SurfaceView or TextureView.

    By tapping on this view the usual camera activity might be started.

    SurfaceView and TextureView should respond to onClick(), or at worse onTouchEvent().

    The final goal is to recognize QR codes within this ImageView, which might make things even more complicated.

    You might say that. :-)

    All of this can be done pretty easy by using the ZXing library

    ZXing is not a library. ZXing is an open source project, publishing the Barcode Scanner app, some integration classes to help you launch the Barcode Scanner app from your app, plus code for non-Android environments.

    There are some recipes online for wrangling ZXing into a library, though I have not tried these. There are some other barcode scanning libraries available, though I have not tried them either. In principle, one of them should be able to allow you to embed the scanning-capable preview into a larger activity.