免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1428 | 回复: 0
打印 上一主题 下一主题

[Android] android平台手电筒开发源代码 [复制链接]

论坛徽章:
1
数据库技术版块每日发帖之星
日期:2016-03-21 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-05-26 11:02 |只看该作者 |倒序浏览
本帖最后由 胡扯 于 2015-05-26 11:04 编辑

android平台手电筒开发源代码,AndroidManifest.xml文件的入口是startapp,这个文件没上传上来,大家可以自己写。
                             

1. [代码]android
  1. /**
  2. * name   : 手电筒主界面
  3. * author : ycgpp@126.com
  4. * date    : 2012-12-21 15:50:17
  5. */
  6. package com.android.app;

  7. import android.app.Activity;
  8. import android.hardware.Camera;
  9. import android.hardware.Camera.Parameters;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.widget.TextView;
  13. import android.widget.Toast;

  14. public class Main extends Activity {

  15.     private boolean isopent = false;
  16.     private Camera camera;

  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         // TODO Auto-generated method stub
  20.         super.onCreate(savedInstanceState);
  21.         View view = View.inflate(this, R.layout.main, null);
  22.         setContentView(view);
  23.         TextView img_but = (TextView) findViewById(R.id.main_img);

  24.         img_but.setOnClickListener(new View.OnClickListener() {

  25.             @Override
  26.             public void onClick(View v) {
  27.                 // TODO Auto-generated method stub
  28.                 if (!isopent) {
  29.                     Toast.makeText(getApplicationContext(), "您已经打开了手电筒", 0)
  30.                             .show();
  31.                     camera = Camera.open();
  32.                     Parameters params = camera.getParameters();
  33.                     params.setFlashMode(Parameters.FLASH_MODE_TORCH);
  34.                     camera.setParameters(params);
  35.                     camera.startPreview(); // 开始亮灯

  36.                     isopent = true;
  37.                 } else {
  38.                     Toast.makeText(getApplicationContext(), "关闭了手电筒",
  39.                             Toast.LENGTH_SHORT).show();
  40.                     camera.stopPreview(); // 关掉亮灯
  41.                     camera.release(); // 关掉照相机
  42.                     isopent = false;
  43.                 }
  44.             }
  45.         });
  46.     }

  47. }
复制代码
2. [代码]布局文件代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:orientation="vertical" >

  6.     <TextView
  7.         android:id="@+id/main_img"
  8.         android:layout_width="fill_parent"
  9.         android:layout_height="fill_parent"
  10.         android:background="@drawable/main_body">
  11.     </TextView>

  12. </LinearLayout>
复制代码
3. [代码]AndroidManifest.xml文件
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.     package="com.android.app"
  3.     android:versionCode="1"
  4.     android:versionName="1.0" >

  5.     <uses-sdk
  6.         android:minSdkVersion="8"
  7.         android:targetSdkVersion="15" />

  8.     <application
  9.         android:icon="@drawable/ic_launcher"
  10.         android:label="@string/app_name"
  11.         android:theme="@style/AppTheme" >
  12.         <activity android:name=".AppStart" >
  13.             <intent-filter>
  14.                 <action android:name="android.intent.action.MAIN" />

  15.                 <category android:name="android.intent.category.LAUNCHER" />
  16.             </intent-filter>
  17.         </activity>
  18.         <activity android:name=".Main" >
  19.         </activity>
  20.     </application>
  21.     <!-- 摄像头、手电筒 -->
  22.     <uses-permission android:name="android.permission.CAMERA" />
  23.     <uses-permission android:name="android.permission.FLASHLIGHT" />

  24.     <uses-feature android:name="android.hardware.camera" />
  25.     <uses-feature android:name="android.hardware.camera.autofocus" />
  26.     <uses-feature android:name="android.hardware.camera.flash" />

  27. </manifest>
复制代码





您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP