Camera preview still black

前端 未结 3 826
你的背包
你的背包 2021-01-01 05:59

I\'m trying the camera preview on my Android applications. When I try on my real devices, it gives me black screen.

This is my code and it doesn\'t throw any error,

相关标签:
3条回答
  • 2021-01-01 06:41

    Bit of an odd issue I've just found relating to black camera preview. In my case it turned out to be because I had the manifest options

    PARTIAL_WAKE_LOCK and also REQUEST_INSTALL_PACKAGES

    <uses-permission android:name="android.permission.PARTIAL_WAKE_LOCK"/>
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
    

    Why these affect the camera like this I don't know - or whether it's just related to the device I'm using - but removing these permissions resolved my issue. It's taken me 2 hours of stripping a project down to figure out where the issue came in!

    0 讨论(0)
  • 2021-01-01 06:59

    Maybe you are being affected by this bug of android Camera bug.

    The workaround to which is proposed here Work around.

    I hope it helps..

    0 讨论(0)
  • 2021-01-01 06:59

    Also refer this Link

    You are calling the last three lines too early. You have to wait for the surface to be prepared before calling setPreviewDisplay() and you have to wait for the surface to be sized (surfaceChanged()) before calling startPreview(). This project has what you need.

    0 讨论(0)
提交回复
热议问题