如何打开“前置摄像头"在Android平台上? [英] How do I open the "front camera" on the Android platform?
本文介绍了如何打开“前置摄像头"在Android平台上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更一般而言,如果一台设备具有多个嵌入式摄像头, 有没有一种方法可以特别初始化其中一个?
More generally, if a device has more than one embedded camera, is there a way to initialize one of them in particular?
我没有在Android参考文档中找到它:
I didn't find it in Android reference documentation:
- https://developer.android.com/reference/android/hardware/Camera.html
- https://developer.android.com/reference/android/hardware/camera2/package-summary.html
- https://developer.android.com/reference/android/hardware/camera2/CameraManager.html
- https://developer.android.com/reference/android/hardware/Camera.html
- https://developer.android.com/reference/android/hardware/camera2/package-summary.html
- https://developer.android.com/reference/android/hardware/camera2/CameraManager.html
三星SHW-M100S有两个摄像头.如果没有提到要使用两台相机,那你知道三星是怎么做到的吗??
Samsung SHW-M100S has two cameras. If there is no reference to use two cameras, 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
文件中添加以下权限:
Add the following permissions in the 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" />
注意::该功能在Gingerbread(2.3)和Up Android版本中可用.
Note: This feature is available in Gingerbread(2.3) and Up Android Version.
这篇关于如何打开“前置摄像头"在Android平台上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文