我正在尝试为我的 motorola fire xt-530 创建一个手电筒应用程序。检查响应切换按钮的此代码。
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
if (getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA_FLASH)) {
camera = Camera.open();
params = camera.getParameters();
List<String> flashModes = params.getSupportedFlashModes();
if (flashModes == null) {
Toast.makeText(getApplicationContext(), "No Flash Found",
Toast.LENGTH_SHORT).show();
} else {
camera.startPreview();
if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
Toast.makeText(getApplicationContext(),
"Torch Mode Found", Toast.LENGTH_SHORT).show();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.takePicture(null, null, null);
} else {
Toast.makeText(getApplicationContext(),
"Torch Mode Not Found", Toast.LENGTH_SHORT).show();
}
}
} else {
Toast.makeText(getApplicationContext(), "Not Available",
Toast.LENGTH_SHORT).show();
}
} else {
camera.stopPreview();
camera.release();
Toast.makeText(getApplicationContext(), "Not Checked",
Toast.LENGTH_SHORT).show();
}
未找到火炬模式。没有扎根。请帮我。