Flash always on camera

Source: Internet
Author: User
 

I'm finding that torch mode is
Generally working fine on 2.1 but I had the same problem with
Samsung Epic and found a hack around it.

Looking at the Params returned by camera. getparameters () when run on
The Samsung Epic, I noticed that the flash-modes it claims to support
Are: Flash-mode-values = OFF, on, auto;

Torch-mode is not listed, implying it's not supported.

However, I found that this model wowould still accept that mode and
Wocould turn the led on! The bad news was that when later setting
Flash-mode back to auto or off left the Led still success! It will not turn
Off until you call camera. Release ().

I guess that's why Samsung dont include it in the list of supported !?!

So... the method I use to toggle torch in a camerahelper class is...

/***** Attempts to set camera flash Torch/flashlight mode on/off * @ Param ISON true = on, false = off * @ return Boolean whether or not we were able to set it */Public Boolean setflashlight (Boolean ISON) {If (mcamera = NULL) {return false;} camera. parameters Params = mcamera. getparameters (); string value; If (ISON) // we are being ask to turn it on {value = camera. parameters. flash_mode_torch ;} Else // we are being asked to turn it off {value = camera. parameters. flash_mode_auto;} Try {Params. setflashmode (value); mcamera. setparameters (Params); string nowmode = mcamera. getparameters (). getflashmode (); If (ISON & nowmode. equals (camera. parameters. flash_mode_torch) {return true;} If (! ISON & nowmode. equals (camera. parameters. flash_mode_auto) {return true;} return false;} catch (exception ex) {mylog. E (mlog_tag, this. getclass (). getsimplename () + "error setting flash mode to:" + value + "" + ex. tostring ());}}

The activities that use this call it as follows...

 
Private void toggleflashlight () {misflashlighton =! Misflashlighton;/*** hack to fix an issue where the Samsung Galaxy will turn torch on, * even though it says it doesnt support torch mode, * But then will not turn it off via this Param. */If (! Misflashlighton & build. manufacturer. specified signorecase ("Samsung") {This. releasecameraresources (); this. initcamera ();} else {boolean result = mcamhelper. setflashlight (misflashlighton); If (! Result) {alertflashlightnotsupported ();}}}

The magic that makes this work in releasecameraresources () is that it
Callcamera. Release ()... and then I have to reinitialize all my camera
Stuff for Samsung devices.

Not pretty but seems to be working for plenty of users.

Note that I do have a report of torch mode not working at all
This code on Nexus One but have been able to dig into it. It definitely
Works on HTC Evo and Samsung Epic.

Hope this helps.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.