Camera.open () does not work.

I am trying to write a custom camera application in android. To do this, I need to open the camera application.

for which I am executing the following code.

Camera Camera = Camera.open ();

but shows an error, for example

open undefined method for type Camera

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

any suggestion..

Thanks, Ravindra Gupta

+6
source share
6 answers

Most likely, you imported the wrong camera class at the top of the source file, which is android.graphics.Camera .

Instead, you need android.hardware.Camera .

thanks

+12
source

I think you have not added a camera resolution. See below - you need to add this to 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" /> 
+2
source

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

+2
source

If none of the above works: check if you need to request the camera’s resolution manually. New permissions for Android (API> 23) are set at runtime rather than setting time. See: https://developer.android.com/training/permissions/requesting.html

+1
source

Create a variable like this:

 android.hardware.Camera camera ; 

and then try opening the method:

 camera = camera.open(); 

// this works on my android studio.

+1
source

I ran into the same problem until I got to the point where older versions of android would work properly for Android Marshmallow, so permission to run was required to continue and view the camera. you can read about it in this link https://developer.android.com/training/permissions/requesting.html

for me, I used a third-party library to do all this for me at this link, and everything is allowed. https://android-arsenal.com/details/1/2804 Hope this helps.

0
source

All Articles