如何检测没有摄像头的可在Android设备?而且如果设备有前置摄像头如何使用它?
How to detect no of camera's available in android device? and also if the device has front camera how to use it?
我的建议是类似doc_180的答案,但应能同时检测前后置摄像头即使是升级Froyo,但如果我没有记错,升级Froyo没有支持前置摄像头,让您总能获得的 frontCam
上升级Froyo一个错误的响应。
What I would suggest is similar to doc_180's answer, but should be able to detect both front and back facing cameras even for Froyo, though if I'm not mistaken, Froyo never supported front-facing cameras, so you'll always get a false response for frontCam
on Froyo.
PackageManager pm = getPackageManager();
boolean frontCam, rearCam;
//Must have a targetSdk >= 9 defined in the AndroidManifest
frontCam = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
rearCam = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
编辑:刚刚意识到这是真的,真的老问题。哦,好吧,希望这可以帮助别人的未来。
Just realized this is a really, really old question. Oh well, hopefully it helps someone in the future.