Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera.open() returns null

When I call mCamera = Camera.open() it returns null, what could be causing this? My device is the Nexus 7.

I already have the permissions set in my AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />
like image 411
Cheetah Avatar asked Aug 21 '12 11:08

Cheetah


3 Answers

Figured it out,

You need to call Camera.open(0).

THIS IS ONLY VALID AND WORKING ON THE NEXUS 7 device, as it only has one camera, so is only useful if targeting that device only.

like image 60
Cheetah Avatar answered Oct 06 '22 01:10

Cheetah


For those who's testing an app on Android 6.0+, make sure that you have implemented Runtime Permission. Because simple permission in your AndroidManifest file is not enough.

like image 24
Elisey Rodriguez Moraga Avatar answered Oct 05 '22 23:10

Elisey Rodriguez Moraga


I solved this issue by following below steps.

  1. Open the "AVD Manager" and select the virtual device you are using

  2. Click on the "Edit" button Click on edit button

  3. In the "Hardware" section, select "New" and add "Configures camera facing back" and click Ok.

  4. In the dropdown next to the entry, select "webcam0" or the one corresponding to the camera you want to use Select the camera you want to use

  5. Stop the AVD and restart again.

like image 22
Srijit Avatar answered Oct 05 '22 23:10

Srijit