Java 您的设备似乎不支持相机(或已锁定)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20666366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
It seems that your device does not support camera(or it is locked)
提问by SBM
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?
Android opencv
示例和教程运行良好,突然有一天我得到了所有这些:"It seems that your device does not support camera (or it is locked). The application will be closed"
请帮忙,我该如何解决?
I have reinstalled opencv and imported again and made new emulators but the problem still persists.
我重新安装了 opencv 并再次导入并制作了新的模拟器,但问题仍然存在。
回答by Jitesh Dalsaniya
Check the camera permission in AndroidManifest.xml.
检查 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..
它为我工作..
回答by Ben Trengrove
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.
刚刚遇到这个问题,我通过杀死使用相机的任何其他应用程序来解决它。我之前的一些教程仍在后台运行。
回答by ahmed_khan_89
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.
这些示例应该可以工作,因为它们使用的是 JavaCamera。当我尝试使用 Native 时,我遇到了这个问题。似乎原生的不适用于每部手机。看到这个。
I have to add that in some devices the openCV native camera doesn't work at all, bug 2359.
我必须补充一点,在某些设备中,openCV 原生相机根本无法工作,错误 2359。
回答by orimen
Go to your device settings -> apps -> YOUR APP -> Permissions -> turn on camera permission..
转到您的设备设置 -> 应用程序 -> 您的应用程序 -> 权限 -> 打开相机权限..
Worked for me..
为我工作..
回答by Geraldo Neto
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.
从 Android 6.0(API 级别 23)开始,用户在应用运行时授予应用权限,而不是在安装应用时授予权限。
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.
这意味着在 Android 23 或更高版本上,除了清单之外,您还需要在运行时请求权限。在这种情况下,相机访问。
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!
希望能帮助到你!
回答by ahmednabil88
In my case, the issue was
My application use Android Camera
in another activity
And another activitywas 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.
在我的情况下,问题是
我的应用程序Android Camera
在另一个活动中使用
并且另一个活动在销毁后没有释放Camera
(锁定它)
并且在我释放Camera
另一个活动后,此对话框将不会再次显示。
So generally to fix this issue
所以一般要解决这个问题
- Check CAMERA permissions
- Check CAMERA not locked (by releasing it after usage in any other activities)
- 检查 CAMERA 权限
- 检查 CAMERA 未锁定(在任何其他活动中使用后将其释放)