Camera API not working on KITKAT

邮差的信 提交于 2019-11-30 07:29:35

I have observed that you are not assigning any surface holder to the camera. Giving a preview surface to the camera is important.

According to the docs here:

http://developer.android.com/guide/topics/media/camera.html

follow the code suggested by the doc. Taking a picture without a preview is a big security concern. Android guys might have fixed this in kitkat.

You might have missed that part of the code while pasting here so as an added concern also check that you are executing your code 'camera.takePicture(null,null,callback)' inside the callback method 'onSurfaceCreated' of SurfaceHolder.

You can get all the relevant code at aforementioned link.

KitKat's garbage collection works differently than previous APIs.

I'm guessing that the PhotoHandler object that you pass to the takePicture() method is getting garbage collected before onPictureTaken can be called.

Try making a PhotoHandler object as in instance variable in your MainActivity.

At the top of the class:

PhotoHandler photoHandler;

Then in onCreate()

photoHandler = new PhotoHandler(getApplicationContext());

Then when you call takePicture():

camera.takePicture(null, null, photoHandler);

Add uses-feature in your manifest file :

<uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />

and check this link. It might be help you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!