// 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);
解决方法
Parameters param = mCamera.getParameters(); Log.i("camera",param.flatten().toString());
然后检查日志
03-18 09:58:08.855: I/camera(32756):
preferred-preview-size-for-video=1280×720;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=1280×720,1920×1080,960×720,720×480,640×480,352×288,320×240,176×144;preview-size=960×720;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=1280×720;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),30000),(30000,30000);jpeg-thumbnail-size-values=160×120,160×90,144×96,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=960×720,1280×720,320×240;picture-size-values=640×480,1024×768,1600×1200,2560×1920,3264×2448,2048×1536,3264×1836,2048×1152,3264×2176;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);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=640×480;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
您可以看到可以使用的值
flash-mode-values=auto,torch;
然后通过代码设置其中一个值
param.set("flash-mode","on"); mCamera.setParameters(param);
你可以尝试一下.