1
sign up log in tour help stack overflow careers Take the 2minute tour × Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required. Android 4.4 : Camera Flashlight blinks only few number of times I have looked into other camera flashlight related problems in stackoverflow, but couldn't find an answer that solves my issue. The flashlight flashes for 68 times and then the app crashes. Here I have a method that calls and in a loop. Could you please let me know where I went wrong? My code can be found here: The logcat output can be see here: blink() cameraon() cameraoff() http://pastebin.com/3LRMwd1J http://pastebin.com/2GTpn8Ux I have tried using surface textures, tried to include in between and but so far no luck. Thread.sleep() cameraon() cameraoff() I use Android 4.4 with latest sdk and jdk versions. I use nexus 5 for testing. Thanks in advance! android flashlight edited Jul 30 '14 at 13:51 asked Jul 30 '14 at 13:19 user3891554 1 1 Please post your code in your question as well, some are unable to get to pastebin due to proxies JBires Jul 30 '14 at 13:52 3 Answers See if my code helps any: https://github.com/wolfhorse/SimpleFlashlight It doesn't blink but it may be a good reference for you. I modified the onClick() event of the toggle button in the SimpleFlashlight app referenced above by adding the code below and it blinks/flashes fine on my Samsung Galaxy S5 without error. EDIT: Thread thread = new Thread(new Runnable() { @Override public void run() { boolean flashOn = false; for (int i= 0;i< 20; i++) { flashOn = !flashOn; toggleFlash(flashOn); try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } } }); thread.start(); Wrapped in new Thread like others suggested here better performance. edited Aug 5 '14 at 20:13 answered Jul 30 '14 at 14:28 wolfhorse 46 4 Thanks will check that out! user3891554 Jul 31 '14 at 10:13 Seems like you should be able to modify that project and call the toggleFlash(boolean turnLightOn) [located in the SimpleFlashlight / app / src / main / java / com / wolfhorse / simpleflashlight / FlashlightActivity.java file] using a Blink() method like you are attempting above. Let me know if it works. wolfhorse Jul 31 '14 at 20:28 It doesn't work :( I was not able to find out the error user3891554 Aug 1 '14 at 9:52

Android 4

Embed Size (px)

DESCRIPTION

hay

Citation preview

  • signup login tour help stackoverflowcareers

    Takethe2minutetour StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.It's100%free,noregistrationrequired.

    Android4.4:CameraFlashlightblinksonlyfewnumberoftimes

    Ihavelookedintoothercameraflashlightrelatedproblemsinstackoverflow,butcouldn'tfindananswerthatsolvesmyissue.Theflashlightflashesfor68timesandthentheappcrashes.HereIhavea methodthatcalls and inaloop.CouldyoupleaseletmeknowwhereIwentwrong?Mycodecanbefoundhere: Thelogcatoutputcanbeseehere:

    blink() cameraon() cameraoff()http://pastebin.com/3LRMwd1J

    http://pastebin.com/2GTpn8Ux

    Ihavetriedusingsurfacetextures,triedtoinclude inbetween and butsofarnoluck.Thread.sleep() cameraon() cameraoff()

    IuseAndroid4.4withlatestsdkandjdkversions.Iusenexus5fortesting.

    Thanksinadvance!

    android flashlight

    editedJul30'14at13:51 askedJul30'14at13:19user38915541 1

    Pleasepostyourcodeinyourquestionaswell,someareunabletogettopastebinduetoproxies JBiresJul30'14at13:52

    3Answers

    Seeifmycodehelpsany:https://github.com/wolfhorse/SimpleFlashlight

    Itdoesn'tblinkbutitmaybeagoodreferenceforyou.

    ImodifiedtheonClick()eventofthetogglebuttonintheSimpleFlashlightappreferencedabovebyaddingthecodebelowanditblinks/flashesfineonmySamsungGalaxyS5withouterror.

    EDIT:

    Threadthread=newThread(newRunnable(){

    @Overridepublicvoidrun(){booleanflashOn=false;for(inti=0;i