而摄像头运行的是Android闪转开/关按钮使用 [英] android flash turn on/off using button while camera is running
问题描述
我看到有liek这么多的问题,但我没有找到任何办法。在我的应用我有我自己的相机有一些选项,并且也有按钮和一个名为 btnFlash
为相机的同时运行开启/关闭照相机的闪光灯。我尝试过很多办法,但没有担任三星电子标签和HTC上。这里是其中的一个
的ImageButton btnFlash =(的ImageButton)findViewById(R.id.btn_flash);
btnFlash.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){ 上下文的背景下= getApplicationContext();
如果(上下文.getPackageManager()。hasSystemFeature(getPackageManager()。FEATURE_CAMERA_FLASH)){
参数PARAMS = mCamera.getParameters();
如果(isFlashOn){
params.setFlashMode(Parameters.FLASH_MODE_OFF);
mCamera.setParameters(PARAMS);
isFlashOn = FALSE;
}其他{
params.setFlashMode(Parameters.FLASH_MODE_ON);
mCamera.setParameters(PARAMS);
isFlashOn = TRUE;
}
}
}
});
- 任何人都可以提出一些很好的教程或某些code?
- 可以相同code对例如工作HTC但不能在三星工作?我的意思是,我可以写了一些code对任何类型的Android设备?
在此先感谢..
通过这个链接。这有助于我在几乎所有的设备实现闪光功能。
导入此项目SVN
HTTP://$c$c.google.com/p/火炬/来源/结帐
I saw that there are many questions liek this but I didn't find any way. In my app I have my own Camera with some options , and also have button named btnFlash
for turning on/off camera's flash light while camera is running. I tried many ways, but nothing worked as on Samsung tab and HTC. here is one of them
ImageButton btnFlash = (ImageButton) findViewById(R.id.btn_flash);
btnFlash.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Context context = getApplicationContext();
if( context .getPackageManager().hasSystemFeature(getPackageManager().FEATURE_CAMERA_FLASH)) {
Parameters params = mCamera.getParameters();
if(isFlashOn) {
params.setFlashMode(Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
isFlashOn = false;
} else {
params.setFlashMode(Parameters.FLASH_MODE_ON);
mCamera.setParameters(params);
isFlashOn = true;
}
}
}
});
- Can anyone suggest some good tutorial or some code?
- Can same code work on e.g. HTC but not work on samsung? I mean can I wrote some code for any type of android device?
Thanks in advance..
Go through this link. This helps me to achieve flash functionality in almost all devices.
Import this SVN project.
http://code.google.com/p/torch/source/checkout
这篇关于而摄像头运行的是Android闪转开/关按钮使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!