我正在开发一个应用程序,该应用程序打开 Flash 以预览图像数据并在完成后关闭 Flash。
public void openFlash() {
try {
flash =false;
previewing=false;
finger_placed=false;
Log.d("", "openFlash");
if(camera==null){
camera = application.getCamera();
preview = Dashboard.preview;
previewHolder = Dashboard.previewHolder;
}
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.setPreviewDisplay(previewHolder);
camera.setPreviewCallback(previewCallback);
camera.startPreview();
} catch (Throwable t) {
Log.e("PreviewDemo-surfaceCallback", "Exception in setPreviewDisplay()", t);
}
}
public void stopPreview() {
try{
Log.d("", "stopPreview");
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.stopPreview();
previewing=false;
}catch (Exception e) {
e.printStackTrace();
}
}
一切正常,直到我锁定屏幕。当我解锁屏幕并使用应用程序时。openFlash 不起作用。并给出如下错误
06-20 12:13:25.725: E/AndroidRuntime(29033): FATAL EXCEPTION: main
06-20 12:13:25.725: E/AndroidRuntime(29033): java.lang.RuntimeException: Method called after release()
06-20 12:13:25.725: E/AndroidRuntime(29033): at android.hardware.Camera.setHasPreviewCallback(Native Method)
06-20 12:13:25.725: E/AndroidRuntime(29033): at android.hardware.Camera.access$600(Camera.java:133)
06-20 12:13:25.725: E/AndroidRuntime(29033): at android.hardware.Camera$EventHandler.handleMessage(Camera.java:805)
06-20 12:13:25.725: E/AndroidRuntime(29033): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 12:13:25.725: E/AndroidRuntime(29033): at android.os.Looper.loop(Looper.java:137)
06-20 12:13:25.725: E/AndroidRuntime(29033): at android.app.ActivityThread.main(ActivityThread.java:4898)
06-20 12:13:25.725: E/AndroidRuntime(29033): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:13:25.725: E/AndroidRuntime(29033): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 12:13:25.725: E/AndroidRuntime(29033): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
06-20 12:13:25.725: E/AndroidRuntime(29033): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
06-20 12:13:25.725: E/AndroidRuntime(29033): at dalvik.system.NativeStart.main(Native Method)
有没有人遇到过这种情况。任何帮助将不胜感激谢谢。