Professional Documents
Culture Documents
tour
signup
help
StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.It's100%free,no
registrationrequired.
stackoverflowcareers
Takethe2minutetour
Android4.4:CameraFlashlightblinksonlyfewnumberoftimes
Ihavelookedintoothercameraflashlightrelatedproblemsinstackoverflow,butcouldn'tfindananswerthatsolvesmyissue.Theflashlight
flashesfor68timesandthentheappcrashes.HereIhavea blink() methodthatcalls cameraon() and cameraoff() inaloop.Couldyou
pleaseletmeknowwhereIwentwrong?Mycodecanbefoundhere:http://pastebin.com/3LRMwd1J Thelogcatoutputcanbeseehere:
http://pastebin.com/2GTpn8Ux
Ihavetriedusingsurfacetextures,triedtoinclude Thread.sleep() inbetween cameraon() and cameraoff() butsofarnoluck.
IuseAndroid4.4withlatestsdkandjdkversions.Iusenexus5fortesting.
Thanksinadvance!
android flashlight
editedJul30'14at13:51
askedJul30'14at13:19
user3891554
1
Pleasepostyourcodeinyourquestionaswell,someareunabletogettopastebinduetoproxies JBires
Jul30'14at13:52
3Answers
Seeifmycodehelpsany:https://github.com/wolfhorse/SimpleFlashlight
Itdoesn'tblinkbutitmaybeagoodreferenceforyou.
EDIT:ImodifiedtheonClick()eventofthetogglebuttonintheSimpleFlashlightappreferenced
abovebyaddingthecodebelowanditblinks/flashesfineonmySamsungGalaxyS5without
error.
Threadthread=newThread(newRunnable(){
@Override
publicvoidrun(){
booleanflashOn=false;
for(inti=0;i<20;i++){
flashOn=!flashOn;
toggleFlash(flashOn);
try{
Thread.sleep(300);
}catch(InterruptedExceptione){
e.printStackTrace();
}
}
}
});
thread.start();
WrappedinnewThreadlikeotherssuggestedherebetterperformance.
editedAug5'14at20:13
answeredJul30'14at14:28
wolfhorse
46