Android flash light app -


I want to make an app for Android device, which will have 2 buttons, one button for "ON" and another " Close ". I have done a pure search for an example and I have seen many examples, but they were very bad wars (for me). What I've created so far is the button and main activity code:

  package com.simple.flashlight; Importroid.os.Bundle; Import android App Import android.graphics.Camera; Import android.hardware.Camera.Parameters; Import android.view.Menu; Import android.view.View; Import android.widget.Button; Public class increases main activity {@ Override Public Empty on Crate (Bundled Saved Instance) {super.onCreate (savedInstanceState); SetContentView (R.layout.main_menue); Button turnOnButtOn = (button) findViewById (R.id.button1); Button TurnOnButtOff = (button) Find ViewById (R.id.button2); TurnOnButtOn.setOnClickListener (New button. OnClickListener () {click on Public Zero (see Cambridge) {}}); }}   

Now I want to do something (pseudo code):

  turnOnButtOn.setOnClickListener (New button. OnClickListener () {public void onClick ( See the camera button) {turnOnTheFlahLight}}); TurnOnButtOn.setOnClickListener (New button. OnClickListener () {click on Public Zero (see camera button) {turnOffTheFlahLight}});   

If there is a complete reference (I'm new to Android) then it would be nice. Thank you

Firstly, you need to add the permission of your manifest to use Flashlight:

  ANDROID: name = "android.permission.FLASHLIGHT" Android: permissionGroup = "android.permission-group.HARDWARE_CONTROLS" Android: protectionLevel = "normal" />   

Turn on the torch to do something like this:

  camera mCam = Camera.open (); Parameter p = mCam.getParameters (); P.setFlashMode (Parameters.FLASH_MODE_TORCH); MCam.setParameters (P); MCam.startPreview ();   

To turn it off:

  mCam.stopPreview (); MCam.release ();    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -