Android Camera開發(fā)手電筒功能
這是一個(gè)簡(jiǎn)單的運(yùn)用Android Camera開發(fā)手電筒功能,AndroidManifest.xml文件的入口是startapp,這個(gè)文件沒(méi)上傳上來(lái),大家可以自己寫。
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(), "您已經(jīng)打開了手電筒", 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(), "關(guān)閉了手電筒", Toast.LENGTH_SHORT).show(); camera.stopPreview(); // 關(guān)掉亮燈 camera.release(); // 關(guān)掉照相機(jī) isopent = false; } } }); } }
布局文件代碼
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="<a 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 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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Flutter?+?Idea?環(huán)境搭建及配置教程
本文主要總結(jié)我實(shí)際搭建的過(guò)程,最后發(fā)現(xiàn)不一定按網(wǎng)上那些博客或者官方文檔寫的來(lái)也可以搭建成功,在這里小編給大家分享下Flutter?+?Idea?環(huán)境搭建及配置教程,感興趣的朋友參考下吧2021-12-12android: targetSdkVersion升級(jí)中Only fullscreen activities can r
這篇文章主要給大家介紹了關(guān)于Android target SDK和build tool版本升級(jí)中遇到Only fullscreen activities can request orientation問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-09-09詳解Android Activity之間切換傳遞數(shù)據(jù)的方法
這篇文章主要介紹了詳解Android Activity之間切換傳遞數(shù)據(jù)的方法 的相關(guān)資料,需要的朋友可以參考下2016-04-04Android中實(shí)現(xiàn)可滑動(dòng)的Tab的3種方式
這篇文章主要介紹了Android中實(shí)現(xiàn)可滑動(dòng)的Tab的3種方式,需要的朋友可以參考下2014-02-02創(chuàng)建子線程對(duì)Android進(jìn)行網(wǎng)絡(luò)訪問(wèn)
這篇文章介紹了Android中創(chuàng)建子線程進(jìn)行網(wǎng)絡(luò)訪問(wèn)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考2021-11-11Android嵌套滾動(dòng)和協(xié)調(diào)滾動(dòng)的多種實(shí)現(xiàn)方法
嵌套的滾動(dòng)主要方式就是這些,這些簡(jiǎn)單的效果我們用協(xié)調(diào)滾動(dòng),如?CoordinatorLayout?也能實(shí)現(xiàn)同樣的效果,這篇文章主要介紹了Android嵌套滾動(dòng)和協(xié)調(diào)滾動(dòng)的多種實(shí)現(xiàn)方法,需要的朋友可以參考下2022-06-06Android使用listview實(shí)現(xiàn)分頁(yè)刷新(線程休眠模擬)
這篇文章主要為大家詳細(xì)介紹了Android使用listview實(shí)現(xiàn)分頁(yè)刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11