Search code examples
androidandroid-camera2textureview

Why is the Android Camera2 preview not showing. It's a dark scene and the TextureView listener is not getting called on activity launch


I followed the basic sample code from Google for Android Camera2 API. https://github.com/googlesamples/android-Camera2Basic.

After I integrated it into my app, it is showing dark scene. No camera output can be seen. It was working fine before integration.


Why is the TextureView listener not getting triggered? Is there some other issue apart from this code?


Solution

  • The problem had nothing to do with the Java code. It worked after I added android:hardwareAccelerated="true" in the CameraActivity <activity> tag in the Manifest.xml file.

    What I found strange in this solution was that the Camera app worked without this property, but after integrating it into a different app, it didn't.

    If anyone has any idea as to why it worked before, but not after integration, kindly share your answer.

    <activity android:name=".CameraActivity"
                android:hardwareAccelerated="true"
                android:screenOrientation="portrait" />