I\'m trying to access the camera on my phone. I\'m writing a simple stub app prior to putting the code in a widget. I\'m not getting very far. The code always throws a runti
I know this question has been answered long time ago, but I would like to add a small thing.
To everyone having the same error, make sure to add this permission in you manifest file:
<uses-permission android:name="android.permission.CAMERA" />
IMPORTANT to use the CAPITAL letters for CAMERA
, as I had the permission with small letters and it didn't work.
Few things:
Why are your use-permissions and use-features tags in your activity tag. Generally, permissions are included as direct children of your <manifest>
tag. This could be part of the problem.
According to the android camera open documentation, a runtime exception is thrown:
if connection to the camera service fails (for example, if the camera is in use by another process or device policy manager has disabled the camera)
Have you tried checking if the camera is being used by something else or if your policy manager has some setting where the camera is turned off?
Don't forget the <uses-feature android:name="android.hardware.camera.autofocus" />
for autofocus.
While I'm not sure if any of these will directly help you, I think they're worth investigating if for no other reason than to simply rule out. Due diligence if you will.
EDIT
As mentioned in the comments below, the solution was to move the uses-permissions
up to above the application tag.
I had the same issue. Tried all the solutions mentioned here but nothing worked. So i rebooted my device and suddenly the issue solved.
For newer android versions that support setting permissions per app (since Marshmallow, 6.0) the permission for camera could be disabled and should be enabled from the app settings.