我知道对此有很多问题,但我认为我面临的问题没有在其中任何一个中得到解决。我写了这个服务的所有不同问题。问题是我在 onStartCommand 方法的所有 try-catch 块中都获得了“成功”,但是回调方法(ShutterCallback 和 PictureCallback)中的日志没有得到处理。我认为这意味着拍摄了照片但没有调用回调,这很奇怪。
Camera cam;
Parameters param;
PictureCallback rawCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
Log.d("CAMERA", "onPictureTaken - raw");
}
};
ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() {
Log.i("CAMERA", "onShutter'd");
}
};
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
cam = Camera.open();
Log.i("CAMERA", "Success");
} catch (RuntimeException e) {
Log.e("CAMERA", "Camera currently unavailable");
e.printStackTrace();
}
try {
param = cam.getParameters();
cam.setParameters(param);
Log.i("CAMERA", "Success");
} catch (Exception e1) {
Log.e("CAMERA", "Parameter problem");
e1.printStackTrace();
}
try {
SurfaceView view = new SurfaceView(this);
cam.setPreviewDisplay(view.getHolder());
cam.startPreview();
Log.i("CAMERA", "Success");
} catch (Exception e) {
Log.e("CAMERA", "Surface Problem");
e.printStackTrace();
}
try {
cam.takePicture(shutterCallback, rawCallback, null);
Log.i("CAMERA", "Success");
} catch (Exception e) {
Log.e("CAMERA", "Click Failure");
e.printStackTrace();
}
cam.release();
return super.onStartCommand(intent, flags, startId);
}