This example saved me a lot of time, thanks for that!
I am just experiencing one issue now, when adding the CameraPreview for the first time the screen goes black for one second. This happens when doing preview.addView(mPreview) in the function safeCameraOpenInView.
For the context I have an activity containing one fragment, this last one is adding the CameraPreview dynamically.
Any clue on that? :)