Android 2.1 的 Camera.Parameters.FLASH_MODE_TORCH 替代品
检查上面的链接。我用它在 Arc S 上进行测试。它有效。
传感器 API 不支持 Xperia Arc S 中的光传感器。您需要使用相机 API 访问光传感器。您可以使用以下代码。
/***
* Attempts to set camera flash torch/flashlight mode on/off
* @param isOn true = on, false = off
* @return boolean whether or not we were able to set it
*/
public boolean setFlashlight(boolean isOn)
{
if (mCamera == null)
{
return false;
}
Camera.Parameters params = mCamera.getParameters();
String value;
if (isOn) // we are being ask to turn it on
{
value = Camera.Parameters.FLASH_MODE_TORCH;
}
else // we are being asked to turn it off
{
value = Camera.Parameters.FLASH_MODE_AUTO;
}
try{
params.setFlashMode(value);
mCamera.setParameters(params);
String nowMode = mCamera.getParameters().getFlashMode();
if (isOn && nowMode.equals(Camera.Parameters.FLASH_MODE_TORCH))
{
return true;
}
if (! isOn && nowMode.equals(Camera.Parameters.FLASH_MODE_AUTO))
{
return true;
}
return false;
}
catch (Exception ex)
{
MyLog.e(mLOG_TAG, this.getClass().getSimpleName() + " error setting flash mode to: "+ value + " " + ex.toString());
}
}
只需从上面的链接中复制代码以使其更清晰。