Android 相机 LED 做手电筒
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
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
|
|
|
|
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 做手电筒相关推荐
- android手电筒功能吗,android通过led实现手电筒功能
本文实例为大家分享了android通过led实现手电筒功能的具体代码,供大家参考,具体内容如下 第一步添加权限: 第二步实现手电筒工具类: import android.hardware.Camera ...
- android 相机闪光灯和手电筒的使用
在android项目中单独使用手电筒或者闪光灯是没有任何问题的.但是在你相机camera打开的时候再打开手电筒功能这时候就或多或少有问题.会报类似于这种错Fail to connect to came ...
- android通过led实现手电筒
第一步 添加权限: <uses-permission android:name="android.permission.CAMERA" /><uses-permi ...
- android手电筒项目代码,Android 开启闪光灯做手电筒 源码-Fun言
权限: 布局 android:layout_width="fill_parent" android:layout_height="fill_parent" an ...
- Android 开启闪光灯做手电筒 源码
权限:<uses-permission android:name="android.permission.FLASHLIGHT" /><uses-permissi ...
- java闪光灯手电筒_Android_Android 开启闪光灯做手电筒的详解,复制代码 代码如下:public class H - phpStudy...
Android 开启闪光灯做手电筒的详解 public class HandLightActivity extends Activity implements OnClickListener{ pri ...
- 深入理解Android相机体系结构之九
该系列文章总目录链接: https://blog.csdn.net/u012596975/article/details/107135938 本篇是<深入理解Android相机体系结构>连 ...
- 基于Android平台开发的手电筒Light
基于Android平台开发的手电筒Light 1. 需求分析: 在现代社会中,手机的功能越来越完善,手电筒就是这些功能中必不可少的一种.当行走在漆黑的道路上,当你在黑暗狭小的地方寻找物品,当你 ...
- android相机采集sdk,Android相机在Android SDK怪怪
我使用相机首次,像大多数第一次的问题接踵而至......Android相机在Android SDK怪怪 我有我的活动肖像,但我的相机是面向非常怪异.它从字面上翻转了图像.因此,如果我从顶部粘住我的手指 ...
最新文章
- linux统计分析命令datamash
- GEF常见问题8:导出到图片
- 商店购物java程序_java操纵数据库-商店购物管理系统
- 移动硬盘计算机无法打开硬盘,移动硬盘无法识别
- iframe在ipad safari的显示
- java期末判断题题库_(java期末考试选择题题库.doc
- Oracle出现ora-01045的解决方法-可用
- 301 302区别_302状态码代表什么,302状态码解决方法
- 8.Nginx 例子
- JS学习总结(2)——变量
- fatjar: eclipse导出工具
- C++ —— string函数
- JS+调用word打印功能实现在Webfrom客户端pos机打印小票(58x210mm)
- MBR、主分区、扩展分区、逻辑分区、活动分区、系统分区、启动分区讲解
- 2019 8 9 STM32F407ADS1526连续转换模式相关配置(采样率达到15000SPS)
- css实现3D书本翻页动画
- 微信小程序 - 实现搜索界面(带热搜、搜索历史和结果页)
- Windows、Linux下安装Maven图文教程
- 工控系统设计(八)组态功能开发
- 发邮件窗体【支持编辑邮件模板,使用wse多线程上传附件及发邮件(带附件)】以及在服务器端自动发邮件...