android平台手電筒開發原始碼

來源:互聯網
上載者:User

標籤:android   style   class   code   http   tar   

android平台手電筒開發原始碼,AndroidManifest.xml檔案的入口是startapp,這個檔案沒上傳上來,大家可以自己寫。1. [代碼]android     jQuery特效/** * name   : 手電筒主介面 * author : [email protected] * 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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.