当前位置: 代码迷 >> Android >> 简易android电筒app
  详细解决方案

简易android电筒app

热度:122   发布时间:2016-04-28 02:45:12.0
简易android手电筒app

[1].[文件] FlashLight.zip ~ 1006KB    下载(376) 跳至 [1] [2]

[2].[代码] [Java]代码 跳至 [1] [2]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
packagecom.syl.flashlight;
 
importandroid.hardware.Camera;
importandroid.hardware.Camera.Parameters;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
 
publicclass MainActivity extendsActivity {
    privateButton open;
    privateButton close;
    privateCamera camera;
    privateboolean isopen = false;
 
    @Override
    protectedvoid onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        open = (Button)findViewById(R.id.openBT);
        close = (Button)findViewById(R.id.closeBT);
        open.setOnClickListener(newMyOnClickListener());
        close.setOnClickListener(newMyOnClickListener());
    }
     
    privateclass MyOnClickListener implementsOnClickListener {
 
        @Override
        publicvoid onClick(View v) {
            // TODO Auto-generated method stub
            switch(v.getId()) {
            caseR.id.openBT:
                camera = Camera.open();
                Parameters params = camera.getParameters();
                params.setFlashMode(Parameters.FLASH_MODE_TORCH);
                camera.setParameters(params);
                camera.startPreview();                 
                break;
            caseR.id.closeBT:
                camera.stopPreview();
                camera.release();
                break;
            }
        }
         
    }
 
}
  相关解决方案