实现Flash的逻辑
1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
view.setOnClickListener( new
OnClickListener() { @Override public
void onClick(View v) { if (!isOpen){ view.setBackgroundResource(R.drawable.open); //改变背景图片 openFlash(); isOpen = true ; } else { view.setBackgroundResource(R.drawable.off); //改变背景图片 closeFlash(); isOpen = false ; } } }); |
打开手电筒
1
2
3
4
5
6
7
8 |
private
void openFlash(){ camera = Camera.open(); //打开照相机 Parameters params
= camera.getParameters(); params .setFlashMode(Parameters.FLASH_MODE_TORCH); //设置照相机参数,FLASH_MODE_TORCH 持续的亮灯,FLASH_MODE_ON 只闪一下 camera.setParameters( params ); camera.startPreview(); //开始亮灯 } |
关掉手电筒
1
2
3
4
5
6 |
private
void closeFlash(){ if (camera != null ){ camera.stopPreview(); //关掉亮灯 camera.release(); //关掉照相机 } } |
Release:
1
2
3
4
5 |
private
void release(){ if (camera != null ){ camera.release(); } } |
参考:android小记之FlashLight --- 高仿小米手电筒
实现手电筒Flash Light 关键代码,布布扣,bubuko.com
原文:http://www.cnblogs.com/linlf03/p/3682385.html