Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera FLASH_MODE_ON not working on Moto X

I have a button that toggles the flash mode between FLASH_MODE_ON/FLASH_MODE_OFF. The toggle works on most phones (I've tested on Nexus 5, S4 & S3) but it fails to flash when taking a picture on Moto X. Any ideas what could be the cause of this?

    // Set camera params
    final Camera.Parameters params = mCamera.getParameters();
    final boolean shouldFlashBeOn = !(Camera.Parameters.FLASH_MODE_ON.equals(params.getFlashMode()));
    params.setFlashMode(shouldFlashBeOn
            ? Camera.Parameters.FLASH_MODE_ON
            : Camera.Parameters.FLASH_MODE_OFF);

    mCamera.setParameters(params);
    mCamera.startPreview();

    // Set ImageButton state
    mImageButtonFlash.setSelected(shouldFlashBeOn);
like image 782
Chris Arriola Avatar asked Mar 17 '14 22:03

Chris Arriola


1 Answers

If I meet this case, I'll check all parameters first. Then find what values I can use. For example, print all parameters by following code

Parameters param = mCamera.getParameters();
Log.i("camera", param.flatten().toString());

Then check the log

03-18 09:58:08.855: I/camera(32756): preferred-preview-size-for-video=1280x720;zoom=0;max-num-detected-faces-hw=5;zoom-supported=true;metering=center;contrast=2;whitebalance=auto;scene-mode=auto;jpeg-quality=100;preview-format-values=yuv420sp,yuv420p;jpeg-thumbnail-quality=100;preview-format=yuv420sp;video-size-values=1280x720,1920x1080,960x720,720x480,640x480,352x288,320x240,176x144;preview-size=960x720;focal-length=3.700000;iso=auto;fast-fps-mode=0;flash-mode-values=auto,off,on,torch;preview-frame-rate-values=30,20,15,10;preview-frame-rate=30;focus-mode-values=auto,infinity,macro,fixed,continuous-picture,continuous-video;jpeg-thumbnail-width=160;video-size=1280x720;scene-mode-values=auto,portrait,landscape,night,beach,snow,sunset,fireworks,sports,party,candlelight,dusk-dawn,fall-color,text,back-light;preview-fps-range-values=(10000,10000),(15000,15000),(15000,30000),(30000,30000);jpeg-thumbnail-size-values=160x120,160x90,144x96,0x0;zoom-ratios=100,102,104,109,111,113,119,121,124,131,134,138,146,150,155,159,165,170,182,189,200,213,222,232,243,255,283,300,319,364,400;preview-size-values=960x720,1280x720,640x480,352x288,320x240;picture-size-values=640x480,960x720,1024x768,1280x720,1600x1200,2560x1920,3264x2448,2048x1536,3264x1836,2048x1152,3264x2176;preview-fps-range=15000,30000;min-exposure-compensation=-4;antibanding=off;max-num-focus-areas=1;vertical-view-angle=49.3;horizontal-view-angle=63;video-stabilization-supported=true;jpeg-thumbnail-height=120;smooth-zoom-supported=false;focus-mode=auto;auto-whitebalance-lock-supported=true;video-frame-format=yuv420sp;picture-format-values=jpeg;max-exposure-compensation=4;focus-areas=(0,0,0,0,0);exposure-compensation=0;exposure-compensation-step=0.5;flash-mode=off;effect-values=none,mono,negative,sepia,solarize,posterize,washed,vintage-warm,vintage-cold,point-blue,point-red-yellow,point-green,cartoonize;picture-size=640x480;max-zoom=30;effect=none;whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight;picture-format=jpeg;focus-distances=0.15,1.20,Infinity;auto-exposure-lock-supported=true;antibanding-values=50hz,off

You can see the values you can use

flash-mode-values=auto,off,on,torch;

Then set the one of the value by the code

param.set("flash-mode", "on");
mCamera.setParameters(param);

You can have a try.

like image 130
yushulx Avatar answered Nov 03 '22 13:11

yushulx