The main changes in the zxing. Cameramanager class under the Zxing.camera package
Switch code added in Cameremanager
provided to other activity to adjust public void Flashhandler () { //camera.startpreview (); Parameters Parameters = Camera.getparameters (); Determine the current status of the flash to modify if (Parameters.FLASH_MODE_OFF.equals (Parameters.getflashmode ())) { turnOn (Parameters); } else if (Parameters.FLASH_MODE_TORCH.equals (Parameters.getflashmode ())) { turnoff (Parameters); } } Open private void TurnOn (Parameters Parameters) { parameters.setflashmode (parameters.flash_mode_torch); Camera.setparameters (parameters); } private void Turnoff (Parameters Parameters) { parameters.setflashmode (parameters.flash_mode_off); Camera.setparameters (parameters); }
Called by ImageButton.
<imagebutton android:id= "@+id/btn_flashlight" android:layout_width= "Wrap_content" android: layout_height= "Wrap_content" android:layout_centerhorizontal= "true" android:layout_centervertical= " True " android:background=" #00000000 " android:src=" @drawable/flashlight "/>
Listening in the captureactivity
In the Inittitle () method, add
Flashimagebutton = (ImageButton) Findviewbyid (r.id.btn_flashlight); Flashimagebutton.setonclicklistener (new Onclicklistener () {//monitor flash button @overridepublic void OnClick (View v) {cameramanager.get (). Flashhandler ();});
OK, fix it!
Android Zxing QR code add flash function