本文介绍了hasSystemFeature(PackageManager.FEATURE_CAMERA)用于设备返回true,没有摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有它的功能,它使用相机功能中有一个应用程序,但部分也可以不带摄像功能的运行。所以我必须把这个在我的清单。I have a application which uses camera functionality in it but part of its functionality can also run without camera feature. SO I have put this in my manifest.<uses-permission android:name="android.permission.CAMERA" /><uses-feature android:name="android.hardware.camera" android:required="false"/>在我的code我检查设备是否有相机或不使用这种and in my code I check whether the device has camera or not using thisfinal boolean deviceHasCameraFlag = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);现在我测试我的code上运行Android 4.0(ICS),并没有摄像头平板电脑。但我仍然得到 deviceHasCameraFlag 真正的价值。被这个奇怪的还是我失去了一些东西。Now I am testing my code on a tablet which runs Android 4.0(ICS) and has no camera. But still I get True value for the deviceHasCameraFlag. Is this weird or am I missing something.我尝试不同的东西,甚至试图在同样的事情上蓝牙功能的平板电脑,甚至不具备蓝牙功能。它工作正常的蓝牙,但给了我真正的相机。I tried different things and even tried the same thing on Bluetooth feature as Tablet even doesn't have Bluetooth feature. It works fine for Bluetooth but gives me true for camera.推荐答案哪个设备是什么呢?你得到的答案是一个bug,和4.0已经很老了时下。仍然运行此版本的许多平板电脑都无法正确雕琢,无论是硬件还是软件配备多个问题。Which device is it? The answer you get is a bug, and 4.0 is very old nowadays. Many tablets that still run this version were not crafted correctly, both hardware and software featuring multiple problems.无论如何,你应该总是ppared处理失败$ P $关于 Camera.open()或 Camera.open(0):例如,在某些情况下,设备上的其他软件将不正常释放相机。Regardless, you should always be prepared to handle failure on Camera.open() or Camera.open(0): for example, in some cases other software on your device will not release the camera gracefully.所以,你的情况,你有一个假阳性,您尝试打开摄像头,它失败了,你继续,如果有设备上没有摄像头,即使软件包管理系统认为 PackageManager.FEATURE_CAMERA 是速效。So, in your case you have a false positive, you try to open the camera, it fails, and you continue as if there is no camera on the device, even if PackageManager thinks that PackageManager.FEATURE_CAMERA is availabe. 这篇关于hasSystemFeature(PackageManager.FEATURE_CAMERA)用于设备返回true,没有摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 02:03