private Camera camera;
public void openLight() //打开闪光灯
{
if(camera!=null)
{
Parameters parameter=camera.getParameters();
parameter.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameter);
}
}
public void closeLight() //关闭闪光灯
{
if(camera!=null)
{
Parameters parameter=camera.getParameters();
parameter.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameter);
}
}
声明权限
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />