Android--sos闪光灯
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android--sos闪光灯相关的知识,希望对你有一定的参考价值。
Camera camera = null;
Parameters parameters = null;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
}
};
// 主开启
public void start() {
handler.post(startThread);
handler.post(closeThread);
}
// 关闭
public void close() {
handler.removeCallbacks(startThread);
handler.removeCallbacks(closeThread);
flashclose();
camera.stopPreview();
camera.release();
camera = null;
}
private void flashopen() {//开启灯
if (camera == null) {
camera = Camera.open();
}
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
}
private void flashclose() {//关闭灯
if (camera == null) {
camera = Camera.open();
}
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
}
Runnable startThread = new Runnable() {
// 将要执行的操作写在线程对象的run方法当中
public void run() {
System.out.println("updateThread");
flashopen();
try {
Thread.sleep(100);
flashclose();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.post(startThread);
}
};
Runnable closeThread = new Runnable() {
// 将要执行的操作写在线程对象的run方法当中
public void run() {
flashclose();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.post(closeThread);
}
};
以上是关于Android--sos闪光灯的主要内容,如果未能解决你的问题,请参考以下文章