码迷,mamicode.com
首页 > 移动开发 > 详细

打开手机手电筒

时间:2015-11-09 12:27:56      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:

<span style="font-size:14px;">package com.jwzhangjie;

import com.jwzhangjie.test.R;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * 手电筒
 * @author jwzhangjie
 *
 */
public class CameraLight extends Activity{

    private Button openLight;
    private boolean status = false;
    private Camera camera;
    private Parameters parameters;
    private CameraLight instance;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cameralight);
        instance = this;
        camera = Camera.open();
        openLight = (Button)findViewById(R.id.openLight);
        openLight.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!status) {
                    openLight.setText("关闭");
                    status = true;
                    new Thread(new TurnOnLight()).start();
                }else {
                    status = false;
                    openLight.setText("打开");
                    instance.parameters.setFlashMode("off");
                    instance.camera.setParameters(instance.parameters);
                }
            }
        });
        
    }
    
    
    private class TurnOnLight implements Runnable{
        @Override
        public void run() {
            instance.parameters = instance.camera.getParameters();
            instance.parameters.setFlashMode("torch");
            instance.camera.setParameters(instance.parameters);
        }
    }
 }
</span>

 

打开手机手电筒

标签:

原文地址:http://www.cnblogs.com/bimingcong/p/4949242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!