Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera.open() is not working android

Tags:

android

camera

I am trying to write a custom camera application in android. For that I need to open the camera application.

for that i am tring following code..

Camera camera = Camera.open();

but is showing error like

method open undefined for type Camera

i did as suggested here http://developer.android.com/reference/android/hardware/Camera.html#open(int)

any suggestion..

Thanks, Ravindra Gupta

like image 271
Ravindra Gupta Avatar asked Dec 20 '13 11:12

Ravindra Gupta


3 Answers

You most likely imported the wrong camera class at the top of your source file, which is android.graphics.Camera.

You need android.hardware.Camera instead.

Thanks

like image 168
Md Abdul Gafur Avatar answered Oct 07 '22 01:10

Md Abdul Gafur


I think you have not added the camera permission. See below - you need to add this in your manifest;

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
like image 42
Sanket990 Avatar answered Oct 07 '22 01:10

Sanket990


Check your imports. I had a similar problem and the Camera object Eclipse chose for me was: import android.graphics.Camera; instead it should be: import android.hardware.Camera;

like image 40
Kanwaljit Singh Avatar answered Oct 07 '22 00:10

Kanwaljit Singh