zoukankan      html  css  js  c++  java
  • 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);
    }

    };

  • 相关阅读:
    Python脚本文件(.py)打包为可执行文件(.exe)即避免命令行中包含Python解释器
    MVC 三步完成增删改查设计
    MVC中使用SqlServerCe
    回车转Tab
    动态代码
    Mvc 用户没有登录跳转到登录界面
    Mvc
    Mvc提交
    EF查询 linq
    EF数据迁移 Migrations
  • 原文地址:https://www.cnblogs.com/laijinquan/p/5961402.html
Copyright © 2011-2022 走看看