0
我正在創建一個led小部件。我可以打開燈,但是當我關閉它時,出現錯誤:無法訪問攝像頭。我不知道爲什麼..Android導致錯誤
public static void setLightMode(Context context)
{
Log.i(TAG,"Opening Camera");
//cam = Camera.open();
Log.i(TAG,"in setLightMode");
if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH))
{
Log.i(TAG,"CAMERA EXISTS");
cam = Camera.open(); //cam is a global value set to null
if(cam != null)
{
Log.i(TAG,"CAMERA NOT NULL");
Parameters p = cam.getParameters();
if(!LIGHT_STATE)
{
Log.i(TAG,"TURNING LED ON");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
setLightState(true);
}
else
{
Log.i(TAG,"TURNING LED OFF");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
cam.stopPreview();
setLightState(false);
}
}
}
}
所以它會打開,但它會遇到錯誤,當我嘗試關閉它。
什麼是錯誤? – ethrbunny