2019独角兽企业重金招聘Python工程师标准>>>

Netkiller Android 手札

http://www.netkiller.cn/android/index.html

Mr. Neo Chan, 陈景峯(BG7NYT)

中国广东省深圳市望海路半岛城邦三期
518067
+86 13113668890

<netkiller@msn.com>

$Id: book.xml 606 2013-05-29 09:52:58Z netkiller $

版权 © 2018 Neo Chan

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

http://www.netkiller.cn
http://netkiller.github.io
http://netkiller.sourceforge.net
微信订阅号 netkiller-ebook (微信扫描二维码)
QQ:13721218 请注明“读者”
QQ群:128659835 请注明“读者”

2018-10

我的系列文档

编程语言

Netkiller Architect 手札 Netkiller Developer 手札 Netkiller Java 手札 Netkiller Spring 手札 Netkiller PHP 手札 Netkiller Python 手札
Netkiller Testing 手札 Netkiller Cryptography 手札 Netkiller Perl 手札 Netkiller Docbook 手札 Netkiller Project 手札 Netkiller Database 手札

10.4. LED flash 做手电筒

<uses-permission android:name="android.permission.FLASHLIGHT" />
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".FlashLightActivity"><Buttonandroid:id="@+id/buttonLight"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="8dp"android:layout_marginTop="8dp"android:layout_marginEnd="8dp"android:layout_marginBottom="8dp"android:text="On"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
package cn.netkiller.camera;import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;import java.security.Policy;public class FlashLightActivity extends AppCompatActivity {private Button buttonLight;private CameraManager cameraManager;private String cameraId;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_flash_light);buttonLight = (Button) findViewById(R.id.buttonLight);Boolean isFlashAvailable = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);if (!isFlashAvailable) {AlertDialog alert = new AlertDialog.Builder(FlashLightActivity.this).create();alert.setTitle("Error");alert.setMessage("Your device doesn't support flash light!");alert.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// closing the applicationfinish();System.exit(0);}});alert.show();return;}cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);try {cameraId = cameraManager.getCameraIdList()[0];} catch (CameraAccessException e) {e.printStackTrace();}buttonLight.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {try {light();} catch (CameraAccessException e) {e.printStackTrace();}}});}public void light() throws CameraAccessException {if (buttonLight.getText().equals("On")) {Toast.makeText(getApplicationContext(), "打开手电筒", Toast.LENGTH_SHORT).show();cameraManager.setTorchMode(cameraId, true);buttonLight.setText("Off");} else {Toast.makeText(getApplicationContext(), "关闭手电筒", Toast.LENGTH_SHORT).show();cameraManager.setTorchMode(cameraId, false);buttonLight.setText("On");}}
}

作者的相关文章

Android EventBus

Android 相机与相册开发

Android i18n 国际化

Android HTTP2 + Oauth2 + Jwt 接口认证实例

Android VideoView 视频播放完成例子(进度条,播放时间,暂停,拖动)

转载于:https://my.oschina.net/neochen/blog/2875492

Android 相机 LED 做手电筒相关推荐

  1. android手电筒功能吗,android通过led实现手电筒功能

    本文实例为大家分享了android通过led实现手电筒功能的具体代码,供大家参考,具体内容如下 第一步添加权限: 第二步实现手电筒工具类: import android.hardware.Camera ...

  2. android 相机闪光灯和手电筒的使用

    在android项目中单独使用手电筒或者闪光灯是没有任何问题的.但是在你相机camera打开的时候再打开手电筒功能这时候就或多或少有问题.会报类似于这种错Fail to connect to came ...

  3. android通过led实现手电筒

    第一步 添加权限: <uses-permission android:name="android.permission.CAMERA" /><uses-permi ...

  4. android手电筒项目代码,Android 开启闪光灯做手电筒 源码-Fun言

    权限: 布局 android:layout_width="fill_parent" android:layout_height="fill_parent" an ...

  5. Android 开启闪光灯做手电筒 源码

    权限:<uses-permission android:name="android.permission.FLASHLIGHT" /><uses-permissi ...

  6. java闪光灯手电筒_Android_Android 开启闪光灯做手电筒的详解,复制代码 代码如下:public class H - phpStudy...

    Android 开启闪光灯做手电筒的详解 public class HandLightActivity extends Activity implements OnClickListener{ pri ...

  7. 深入理解Android相机体系结构之九

    该系列文章总目录链接: https://blog.csdn.net/u012596975/article/details/107135938 本篇是<深入理解Android相机体系结构>连 ...

  8. 基于Android平台开发的手电筒Light

    基于Android平台开发的手电筒Light 1.     需求分析: 在现代社会中,手机的功能越来越完善,手电筒就是这些功能中必不可少的一种.当行走在漆黑的道路上,当你在黑暗狭小的地方寻找物品,当你 ...

  9. android相机采集sdk,Android相机在Android SDK怪怪

    我使用相机首次,像大多数第一次的问题接踵而至......Android相机在Android SDK怪怪 我有我的活动肖像,但我的相机是面向非常怪异.它从字面上翻转了图像.因此,如果我从顶部粘住我的手指 ...

最新文章

  1. linux统计分析命令datamash
  2. GEF常见问题8:导出到图片
  3. 商店购物java程序_java操纵数据库-商店购物管理系统
  4. 移动硬盘计算机无法打开硬盘,移动硬盘无法识别
  5. iframe在ipad safari的显示
  6. java期末判断题题库_(java期末考试选择题题库.doc
  7. Oracle出现ora-01045的解决方法-可用
  8. 301 302区别_302状态码代表什么,302状态码解决方法
  9. 8.Nginx 例子
  10. JS学习总结(2)——变量
  11. fatjar: eclipse导出工具
  12. C++ —— string函数
  13. JS+调用word打印功能实现在Webfrom客户端pos机打印小票(58x210mm)
  14. MBR、主分区、扩展分区、逻辑分区、活动分区、系统分区、启动分区讲解
  15. 2019 8 9 STM32F407ADS1526连续转换模式相关配置(采样率达到15000SPS)
  16. css实现3D书本翻页动画
  17. 微信小程序 - 实现搜索界面(带热搜、搜索历史和结果页)
  18. Windows、Linux下安装Maven图文教程
  19. 工控系统设计(八)组态功能开发
  20. 发邮件窗体【支持编辑邮件模板,使用wse多线程上传附件及发邮件(带附件)】以及在服务器端自动发邮件...

热门文章

  1. 【mysql笔试题】
  2. 将Ubuntu安装在U盘上,实现即插即用
  3. JUC线程池之线程池架构
  4. 分布式一致性算法介绍
  5. Js清除Cookie
  6. 假设检验中的两类错误
  7. 花狐狸股市操作系统说明书
  8. CAD绘制导入wall并颗粒分组
  9. sequoiaDB连接mysql_SequoiaDB 巨杉数据库Docker镜像使用教程
  10. 支持多种格式转换的PDF转换成PPT转换器