如何打开“前置摄像头”在Android平台? [英] How to open "front camera" on android platform?
问题描述
更一般地说,如果一个设备有多个嵌入式摄像机,
有什么办法来初始化其中的一个?
More generally, If a device has more than one embedded camera, is there any way to initialize one of them in particular?
t在android中引用docs:
I didn't find it in android reference docs:
https://developer.android.com/reference/android/hardware/Camera.html
https://developer.android.com/reference/android/hardware/camera2/package-summary.html
< a href =https://developer.android.com/reference/android/hardware/camera2/CameraManager.html =nofollow noreferrer> https://developer.android.com/reference/android/hardware/camera2 /CameraManager.html
三星SHW-M100S有2个相机。
如果没有参考使用2个凸轮,任何想法如何三星做..?
Samsung SHW-M100S have 2 cameras. If there is no reference to use 2 cams, Any idea how samsung did..?
推荐答案
private Camera openFrontFacingCameraGingerbread() {
int cameraCount = 0;
Camera cam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
try {
cam = Camera.open(camIdx);
} catch (RuntimeException e) {
Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
}
}
}
return cam;
}
在 AndroidManifest.xml
file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<版本。
Note: This feature is available in Gingerbread(2.3) and Up Android Version.
这篇关于如何打开“前置摄像头”在Android平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!