[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 | package com.syl.flashlight; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private Button open; private Button close; private Camera camera; private boolean isopen = false ; @Override protected void 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( new MyOnClickListener()); close.setOnClickListener( new MyOnClickListener()); } private class MyOnClickListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.openBT: camera = Camera.open(); Parameters params = camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(params); camera.startPreview(); break ; case R.id.closeBT: camera.stopPreview(); camera.release(); break ; } } } } |