Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,693 members, 7,816,834 topics. Date: Friday, 03 May 2024 at 06:18 PM

Android Torch Light / Flash Light App Tutorial - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Android Torch Light / Flash Light App Tutorial (2016 Views)

Fix For Blackberry Torch Virtual Keyboard Bug. (2) (3) (4)

(1) (Reply) (Go Down)

Android Torch Light / Flash Light App Tutorial by nollyj: 11:20am On Apr 21, 2015

In this tutorial we are going to learn how to create android Torch light / Flash light app. This is one of the common utility apps you find in Google Play. If you have wondered how to develop this android app or you want to code your own android torch light app, this tutorial is for you.

The concept behind android Torch light app is that the app makes use of the device camera Flash Mode to turn on and off the camera flash.

This will not work on a device that does not support any camera flash but we will have to put a check in place so that our app will not end up crashing.

Before we start, the first thing I will do is to list the environment and tools I used in this android tutorial but feel free to use whatever environment or tools you are familiar with.

Windows 7

Android Studio

Samsung Galaxy Fame Lite

Min SDK 14

Target SDK 19

To create a new android application project, following the steps as stipulated below.

Go to File menu

Click on New menu

Click on Android Application

Enter Project name: AndroidFlashLightApp

Package: com.inducesmile.androidflashlightapp

Keep other default selections.

Continue to click on next button until Finish button is active, then click on Finish Button/

Once you are done with creating your project, make sure you change the package name if you did not use the same package.

http://inducesmile.com/android/android-torch-light-flash-light-app-tutorial/

1 Like

Re: Android Torch Light / Flash Light App Tutorial by nollyj: 11:23am On Apr 21, 2015
Manifest.xml File
Since we are going to access and make use of some hardware resources in our device like camera, we are going to use some android permissions. The list is as follows but note that you can remove the one you free is not necessary

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>


The Wake lock android permission is use to keep the screen alive when using our app. The updated version of our project Manifest.xml file is shown below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="androidflashlightapp" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Re: Android Torch Light / Flash Light App Tutorial by nollyj: 11:36am On Apr 21, 2015
Activity_main.xml file
Open the main layout of your project, Since I used the default Main Activity, my corresponding layout for this page is activity_main.xml.

We are going to add an Imagebutton View in the layout file. In your IDE you can choose the layout design view and drag and drop an ImageButton to the layout. If you prefer to use code view, then copy and paste the code below into your layout file.

As you can see the layout is very simple. We will use the ImageButton View to turn on and off our flash light.

<RelativeLayout xmlns:android=""
xmlns:tools=""
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/background"
tools:context=".MainActivity">

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/flash_light"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/buttonoff"
android:background="@android:color/transparent"
android:contentDescription="@null"
android:layout_marginTop="140dp" />
</RelativeLayout>
Re: Android Torch Light / Flash Light App Tutorial by Nobody: 7:16pm On May 08, 2015
This is no tutorial

(1) (Reply)

A Must Read: Interview With Seun Osewa (owner Of Nairaland) / Question on Java Development / Tech Don Cast!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 27
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.