It seems that your device does not support camera(or it is locked)
Asked Answered
S

6

19

Android opencv samples and tutorials were running fine and suddenly one day I get this for all of those:
"It seems that your device does not support camera (or it is locked). The application will be closed"
Please help, how to I can fix it?

I have reinstalled opencv and imported again and made new emulators but the problem still persists.

Sacci answered 18/12, 2013 at 19:5 Comment(3)
turn off the device and re-boot. Try reinstalling opencv again.Unsearchable
take a look at this: answers.opencv.org/question/1574/camera-not-workingKamkama
I had meet same issue, and it solved with the following way. See https://mcmap.net/q/665067/-it-seems-that-your-device-does-not-support-cameraDonny
W
37

Go to your device settings -> apps -> YOUR APP -> Permissions -> turn on camera permission..

Worked for me..

Wilser answered 26/6, 2016 at 13:51 Comment(4)
This is what I had to do. Not sure why the permission wasn't granted.Spirochete
@AutonomousApps, Because you are using an API/Build Tools > 23Wilser
Worked for me, but requesting the permissions from the user as in Geraldo's answer should be better.Chambless
To solve it on runtime, not manually, check my answer here: https://mcmap.net/q/627983/-it-seems-that-your-device-does-not-support-camera-or-it-is-locked.Wedlock
M
19

Check the camera permission in AndroidManifest.xml.

<uses-permission android:name="android.permission.CAMERA"/>

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

Its working for me..

Musil answered 13/2, 2014 at 11:46 Comment(0)
W
11

From the Android Docs:

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.

It means that on Android 23 or above, besides the manifest, you need to request permission on runtime as well. In this case, camera access.

To do this, you can use the code below:

// First check android version 
if (MyVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
//Check if permission is already granted
//thisActivity is your activity. (e.g.: MainActivity.this)
    if (ContextCompat.checkSelfPermission(thisActivity,
                    Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {

        // Give first an explanation, if needed.
        if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
                Manifest.permission.CAMERA)) {

            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(thisActivity,
                    new String[]{Manifest.permission.CAMERA},
                    1);
        }
    }
}

You can also handle the request response, as described on the docs.

Hope it helps!

Wedlock answered 20/5, 2017 at 15:55 Comment(2)
Where do I add this code? This doesnt seem to be jhava code at all, getting many errors when I try to paste it somewhere in MainActivity, please clarify where to addCotswold
Hi, Mich! It is Java. I suggest you to read the docs linked on the answer so that you get more detailed and updated information.Wedlock
O
2

Just had this problem and I solved it by killing any other apps that were using the camera. I had some previous tutorials still running in the background.

Orebro answered 26/2, 2014 at 0:4 Comment(0)
D
2

In my case, the issue was
My application use Android Camera in another activity
And another activity was not release the Camera after use it on Destroyed (lock it)
And after I release the Camera on the another activity, this dialog will not showed again.

So generally to fix this issue

  1. Check CAMERA permissions
  2. Check CAMERA not locked (by releasing it after usage in any other activities)
Documentation answered 1/1, 2019 at 5:45 Comment(1)
related question about release #11496342Documentation
A
0

The samples should work because they are using the JavaCamera. I get this problem when I tried to use the Native one. It seems to be that the native one doesn't work for ervery phone. see this.

I have to add that in some devices the openCV native camera doesn't work at all , bug 2359.

Acerbate answered 24/1, 2015 at 22:15 Comment(1)
I faced a similar issue when running on emulator, and the solution was: Go emulator, Setting->Apps->my_app->Permissions and then enable "Camera". I found it being requested but not enabled.Taitaichung

© 2022 - 2024 — McMap. All rights reserved.