java – It seems that your device does not support camera(or it is locked)-ThrowExceptions

Exception or error:

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.

How to solve:

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

Worked for me..

###

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..

###

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!

###

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.

###

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)

###

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.

Leave a Reply

Your email address will not be published. Required fields are marked *