gpt4 book ai didi

android - torch 应用安卓

转载 作者:行者123 更新时间:2023-11-30 04:42:29 24 4
gpt4 key购买 nike

你好,我想在 android 中实现 torch 应用程序,所以这是我的代码

    setContentView(R.layout.main);
camera = Camera.open();
if(camera == null)
Toast.makeText(getBaseContext(),"CAMERA FAILED", Toast.LENGTH_LONG).show();
else
Toast.makeText(getBaseContext(),"camera opened",Toast.LENGTH_LONG).show();
}
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
if(camera!=null)
{
Toast.makeText(getBaseContext(),"came to volume up",Toast.LENGTH_LONG).show();
Parameters params = camera.getParameters();
params.setFlashMode( Parameters.FLASH_MODE_ON );
camera.setParameters(params);

}
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_UP) {
Parameters params = camera.getParameters();
params.setFlashMode( Parameters.FLASH_MODE_OFF );
camera.setParameters(params);
camera.release();
camera = null;
Toast.makeText(getBaseContext(),"came to volume down",Toast.LENGTH_LONG).show();
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}

为什么这段代码不起作用???

最佳答案

杜尔迦,

我相信你想要FLASH_MODE_TORCH不是FLASH_MODE_ON当您按下音量增大键时。

可能需要以下权限:FLASHLIGHTCAMERA

关于android - torch 应用安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5715293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com