如何检测没有摄像头的可在Android设备?而且如果设备有前置摄像头如何使用它? [英] How to detect no of camera's available in android device? and also if the device has front camera how to use it?

查看:104
本文介绍了如何检测没有摄像头的可在Android设备?而且如果设备有前置摄像头如何使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测没有摄像头的可在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.

这篇关于如何检测没有摄像头的可在Android设备?而且如果设备有前置摄像头如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆