For this you should do like :

  1. Check whether flash light isavailable or not ?

  2. If yes then Turn Off/On

  3. If no then you can do whatever according to your app.needs

For Checking availability of flash in device:

You can use the following

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)

which will return true if a flash is available, false if not.

See http://developer.android.com/reference/android/content/pm/PackageManager.html for more information.

Camera mCamera = null;
boolean mbTorchEnabled = false;

public void openflashlight(View v) {// Here are class declarationsCamera.Parameters mParameters;if (mCamera == null)mCamera = Camera.open();// This one is inside my OnClickListenerif (v.getId() == R.id.flashlight) {mParameters = mCamera.getParameters();if (mbTorchEnabled) {mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);mCamera.stopPreview();mCamera.release();mCamera = null;} else {mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);mCamera.setParameters(mParameters);mCamera.startPreview();}mbTorchEnabled = !mbTorchEnabled;}}

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />



更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 各种款式的别致的 Android 体恤衫
  2. Android 360开源全面插件化框架RePlugin
  3. Android下常见的内存泄露
  4. Android(安卓)-- Options Menu,Context M
  5. Android Audio控制和MediaButton远程控制
  6. 细看Google Android的开源姿态
  7. NDK编译.so动态库
  8. Android 使用Vitamio打造自己的万能播放
  9. 关于Android中android:marginBottom不起
  10. Android(安卓)鐨勭郴缁熷睘鎬?SystemProp