iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android Camera开发手电筒功能
  • 321
分享到

Android Camera开发手电筒功能

Android 2022-06-06 08:06:47 321人浏览 安东尼
摘要

这是一个简单的运用Android Camera开发手电筒功能,AndroidManifest.xml文件的入口是startapp,这个文件没上传上来,大家可以自己写。 fla

这是一个简单的运用Android Camera开发手电筒功能,AndroidManifest.xml文件的入口是startapp,这个文件没上传上来,大家可以自己写。

flashlight.java


package com.android.app;
import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast; 
public class Main extends Activity {
 private boolean isopent = false;
 private Camera camera; 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  View view = View.inflate(this, R.layout.main, null);
  setContentView(view);
  TextView img_but = (TextView) findViewById(R.id.main_img);
  img_but.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    if (!isopent) {
     Toast.makeText(getApplicationContext(), "您已经打开了手电筒", 0)
       .show();
     camera = Camera.open();
     Parameters params = camera.getParameters();
     params.setFlashMode(Parameters.FLASH_MODE_TORCH);
     camera.setParameters(params);
     camera.startPreview(); // 开始亮灯
     isopent = true;
    } else {
     Toast.makeText(getApplicationContext(), "关闭了手电筒",
       Toast.LENGTH_SHORT).show();
     camera.stopPreview(); // 关掉亮灯
     camera.release(); // 关掉照相机
     isopent = false;
    }
   }
  });
 }
}

布局文件代码


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="<a href="Http://schemas.android.com/apk/res/android"" rel="nofollow" target="_blank">http://schemas.android.com/apk/res/android"</a>
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 <TextView
  android:id="@+id/main_img"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/main_body">
 </TextView>
</LinearLayout>

AndroidManifest.xml文件


<manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android"" rel="nofollow" target="_blank">http://schemas.android.com/apk/res/android"</a>
 package="com.android.app"
 android:versionCode="1"
 android:versionName="1.0" > 
 <uses-sdk
  android:minSdkVersion="8"
  android:targetSdkVersion="15" />
 <application
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name"
  android:theme="@style/AppTheme" >
  <activity android:name=".AppStart" >
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <cateGory android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
  <activity android:name=".Main" >
  </activity>
 </application>
 <!-- 摄像头、手电筒 -->
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.FLASHLIGHT" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />
 <uses-feature android:name="android.hardware.camera.flash" />
</manifest>
您可能感兴趣的文章:Android 7.0 手电筒控制实现android通过led实现手电筒功能Android实现简单手电筒功能Android实现手电筒电源键关闭功能Android开启闪光灯的方法 Android打开手电筒功能Android studio编写简单的手电筒APPAndroid中编写简单的手电筒小应用的实例教程Android 通用型手电筒代码Android 开启闪光灯做手电筒的详解Android手电筒兼容各个手机与版本


--结束END--

本文标题: Android Camera开发手电筒功能

本文链接: https://www.lsjlt.com/news/24541.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作