android平台手电筒开发源代码
2014-06-24 14:47
190 查看
android平台手电筒开发源代码,AndroidManifest.xml文件的入口是startapp,这个文件没上传上来,大家可以自己写。
1. [代码]android jQuery特效
/**
* name : 手电筒主界面
* author : ycgpp@126.com
* date : 2012-12-21 15:50:17
*/
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();http://www.huiyi8.com/webyuanma/
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;
}
}
});
}
}
2. [代码]布局文件代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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>
3. [代码]AndroidManifest.xml文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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>
1. [代码]android jQuery特效
/**
* name : 手电筒主界面
* author : ycgpp@126.com
* date : 2012-12-21 15:50:17
*/
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();http://www.huiyi8.com/webyuanma/
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;
}
}
});
}
}
2. [代码]布局文件代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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>
3. [代码]AndroidManifest.xml文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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平台手电筒开发源代码
- android平台手电筒开发源代码
- android平台手电筒开发源代码
- [安卓开发] Android 自己做双向手电筒 源代码
- android 开发平台的搭建
- qualcomm 7k android 平台的开发1
- Android开发入门(-)之开发平台搭建
- 工作流的设计,业务流程图的绘制与编辑,工作流软件,工作流源代码组件库,开发平台,开发引擎
- 谈谈国内开发的Linux手机软件平台Broncho,兼谈Android、Openmoko等[转]
- 开发者谈iPhone和Android平台开发
- 索爱针对Android平台推出WebSDK, 主要是为其Android手机开发应用。
- 谈谈国内开发的Linux手机软件平台Broncho,兼谈Android、Openmoko等[转]
- 实例详解快捷搭建Android手机开发平台
- Android开发平台搭建(Windows)
- Windows平台下搭建Android原生C/C++开发环境(转)
- Android 1.5r3+Eclipse+ADT 0.9.1+JDK 6u14=Android手机开发平台
- Android的开发配置篇(linux平台)
- 在google Android平台上开发的几款3D游戏!
- Windows平台下搭建Android原生C/C++开发环境
- android 平台上的手机应用开发 how to user HttpUrlConnection POST Much Fields to Web Server ?