Android Zxing QR code add flash function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.