React-native-barcodescanner Sweep Code The second time go in black screen

Source: Internet
Author: User

React-native (React-native-barcodescanner) sweep code The first time in the normal but after the black screen, said on the internet is a new scene to pop out (may be my version and the online version of the different results), But I pop off the second go in or black screen, tangled for a long time, guess is called the camera did not release the cause, but only move Barcodescanner source, looked at the project file directory as follows:



The code for many other locations in the three files in the React-native-barcodescanner project has been modified (in single case mode, Remove the first if method in the Setcameratype method in Reactbarcodescannerview.java, etc., but no, no more, just say the correct way to modify in my environment:

To modify the Setcameratype method in Reactbarcodescannerview.java, the original code:

public void Setcameratype (String type) {
if (mprevcameratype.equals (type)) {

Return
}

Stopcamera ();

Camera.camerainfo camerainfo = new Camera.camerainfo ();


Mcameraid =-1;


for (int cameraid = 0; Cameraid < Camera.getnumberofcameras (); cameraid++) {
Camera.getcamerainfo (Cameraid, camerainfo);


if (Type.equals ("Back") && camerainfo.facing = = Camera.CameraInfo.CAMERA_FACING_BACK) {
Mcameraid = Cameraid;
Break
}


if (Type.equals ("front") && camerainfo.facing = = Camera.CameraInfo.CAMERA_FACING_FRONT) {
Mcameraid = Cameraid;
Break
}
}


Startcamera (Mcameraid);


if (Type.equals ("Back")) {
Setflash (torchmodeisenabled ());
}


Mprevcameratype = type;
}


Modified code:

public void Setcameratype (String type) {
if (mprevcameratype.equals (type)) {
Stopcamera ();
Return
}


Camera.camerainfo camerainfo = new Camera.camerainfo ();


Mcameraid =-1;


for (int cameraid = 0; Cameraid < Camera.getnumberofcameras (); cameraid++) {
Camera.getcamerainfo (Cameraid, camerainfo);


if (Type.equals ("Back") && camerainfo.facing = = Camera.CameraInfo.CAMERA_FACING_BACK) {
Mcameraid = Cameraid;
Break
}


if (Type.equals ("front") && camerainfo.facing = = Camera.CameraInfo.CAMERA_FACING_FRONT) {
Mcameraid = Cameraid;
Break
}
}


Startcamera (Mcameraid);


if (Type.equals ("Back")) {
Setflash (torchmodeisenabled ());
}


Mprevcameratype = type;
}


Above the red Word for the modified code location

Related Article

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.