我有一些设置闪光模式的例子,不能让它工作。我在相机交换中使用它:
final ImageButton button1 = (ImageButton) findViewById(R.id.bt_camera);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
camera.release();
idCam.id = idCamera(idCam.id);
camera = Camera.open(idCam.id);
Camera.Parameters parametro = camera.getParameters();
parametro.setFlashMode(Parameters.FLASH_MODE_ON);
camera.setParameters(parametro);
camera.startPreview();
try {
camera.setPreviewDisplay(camHolder.id);
} catch (IOException e) {
e.printStackTrace();
}
}
});
如果没有 flash 参数,swap 可以正常工作。
清单中包含的权限:
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
<uses-permission android:name="android.permission.CAMERA" />
但日志返回:
05-21 09:25:02.985: D/IPCThreadState(24048): [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x64fca0
05-21 09:25:03.260: D/AndroidRuntime(24048): Shutting down VM
05-21 09:25:03.260: W/dalvikvm(24048): threadid=1: thread exiting with uncaught exception (group=0x40ca4258)
05-21 09:25:03.283: E/AndroidRuntime(24048): FATAL EXCEPTION: main
05-21 09:25:03.283: E/AndroidRuntime(24048): java.lang.RuntimeException: setParameters failed
05-21 09:25:03.283: E/AndroidRuntime(24048): at android.hardware.Camera.native_setParameters(Native Method)
05-21 09:25:03.283: E/AndroidRuntime(24048): at android.hardware.Camera.setParameters(Camera.java:1714)
05-21 09:25:03.283: E/AndroidRuntime(24048): at br.com.JairoFilho.teste4.Login$1.onClick(Login.java:66)