我有一個問題。我想從 執行示例應用程序http://www.vogella.com/articles/AndroidCamera/article.html 它的工作原理。 但當代碼CAMERA_FACING_FRONT變化CAMERA_FACING_BACK我看到的logcat:相機錯誤-1背部照相機android不工作
我執行它在我的三星Galaxy SII
private int findFrontFacingCamera() {
int cameraId = -1;
// Search for the front facing camera
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
Log.d(DEBUG_TAG, "Camera found");
cameraId = i;
break;
}
}
return cameraId;
}
當前代碼
private int findFrontFacingCamera() {
int cameraId = -1;
// Search for the front facing camera
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
Log.d(DEBUG_TAG, "Camera found " + info.facing);
cameraId = i;
break;
}
}
return cameraId;
}
logCat:
04-30 21:14:36.400: D/MakePhotoActivity(8793): Camera found 0
04-30 21:14:36.400: I/Camera(8793): sendBroadcast intent.stop.app-in-app
04-30 21:14:36.650: D/libEGL(8793): loaded /system/lib/egl/libEGL_mali.so
04-30 21:14:36.655: D/libEGL(8793): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-30 21:14:36.660: D/libEGL(8793): loaded /system/lib/egl/libGLESv2_mali.so
04-30 21:14:36.665: D/(8793): Device driver API match
04-30 21:14:36.665: D/(8793): Device driver API version: 10
04-30 21:14:36.665: D/(8793): User space API version: 10
04-30 21:14:36.665: D/(8793): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
04-30 21:14:36.685: D/OpenGLRenderer(8793): Enabling debug mode 0
04-30 21:16:21.695: D/dalvikvm(8793): WAIT_FOR_CONCURRENT_GC blocked 0ms
04-30 21:16:21.775: D/dalvikvm(8793): GC_EXPLICIT freed 78K, 14% free 9467K/10883K, paused 9ms+4ms, total 82ms
04-30 21:16:22.010: E/Camera(8793): Error -1
其餘的代碼
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// do we have a camera?
if (!getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
.show();
} else {
cameraId = findFrontFacingCamera();
if (cameraId < 0) {
Toast.makeText(this, "No front facing camera found.",
Toast.LENGTH_LONG).show();
} else {
camera = Camera.open(cameraId);
}
}
}
public void onClick(View view) {
camera.takePicture(null, null,
new PhotoHandler(getApplicationContext()));
}
權限:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
是否找到「找到相機」?你可以嘗試登錄numberOfCameras? – pt2121 2013-04-30 19:04:27