我正在尝试使用实际设备通过Camera2 API访问前置摄像头
尝试时出现问题
cameraManager.openCamera(..,..,..)
try {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraID);
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Time out waiting to lock camera opening.");
}
manager.openCamera(mCameraID, mStateCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
Log.e("mr", "OpenCamera - Camera Access Exception");
} catch (IllegalArgumentException e) {
Log.e("mr", "OpenCamera - Illegal Argument Exception");
} catch (SecurityException e) {
e.printStackTrace();
Log.e("mr", "OpenCamera - Security Exception:");
} catch (InterruptedException e) {
Log.e("mr", "OpenCamera - Interrupted Exception");
}
相机经理说
I/CameraManagerGlobal:连接到相机服务
来自这个CameraManager.java函数
private void connectCameraServiceLocked() {
// Only reconnect if necessary
if (mCameraService != null) return;
Log.i(TAG, "Connecting to camera service");
然后我的 GLSurfaceView 保持空白
AndroidMainfest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
PS:
- 它适用于后置摄像头
- 它适用于 nexus 6 API 23 模拟器
- Android M 在运行时请求权限
- 我使用GLSurfaceView作为取景器
- 前置摄像头在使用普通CameraAPI和TextureView的同一设备上完美运行
- 试图卸载/重新启动/清除缓存
- 我使用的设备是Sony Z5 premium