下面的代码在 Wildfire S 上运行良好,但在摩托罗拉 RAZR 上运行良好,它是如何实现的以及如何修复它。我看到很少有关于这个的帖子,但没有答案。
if (camera==null)
camera=Camera.open();
camera_parameters = camera.getParameters();
flash_mode = camera_parameters.getFlashMode();
camera_parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(camera_parameters);
the_button = (ToggleButton) findViewById(R.id.flashlightButton);
if (the_button.isChecked()){
camera.startPreview();
the_button.setKeepScreenOn(true);
public void onToggleClicked(View v) {
if (((ToggleButton) v).isChecked()) {
camera.setParameters(camera_parameters);
camera.startPreview();
v.setKeepScreenOn(true);
} else {
camera.stopPreview();
v.setKeepScreenOn(false);
}
}
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.flash" />