抱歉我的英文。
我已经编写了这个代码,在我的三星Galaxy s上使用前置摄像头。但该应用程序打开我的默认相机,工作非常糟糕。 我想使用前置摄像头录制视频,但前置摄像头不能打开它。
有什么想法吗?
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.content.Intent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
public class Main extends Activity implements SurfaceHolder.Callback {
private static final String TAG = null;
private Camera mcamera;
private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private boolean mPreviewRunning;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //full screen
setContentView(R.layout.main);
mSurfaceView = (SurfaceView)findViewById(R.id.camerasurf);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
if (mPreviewRunning)
mcamera.stopPreview();
Camera.Parameters p = mcamera.getParameters();
p.set("camera-id", 2);
p.setPreviewSize(640, 480);
mcamera.setParameters(p);
try {
mcamera.setPreviewDisplay(arg0);
mcamera.startPreview();
mPreviewRunning = true;
} catch (IOException e) {
}
}
public void surfaceCreated(SurfaceHolder holder) {
mcamera=Camera.open();
}
public void surfaceDestroyed(SurfaceHolder holder) {
mcamera.stopPreview();
mPreviewRunning = false;
mcamera.release();
}
}
在我的清单上我写了这个。
<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"/>
我的错误在哪里? TNX