Android Studio uses zxing two-dimensional code scanning, process and problem rollup

Source: Internet
Author: User
Tags case statement switch case

This article describes two ways for Android studio to import zxing, for informational purposes only. 1. Direct Complie Import

1.1 Build.gradle Direct Complie of items that need to be scanned using zxing for two-dimensional code

<code class= "Hljs nginx has-numbering" style= "Display:block"; padding:0px; Background:transparent; Color:inherit; Box-sizing:border-box; font-family: "Source Code Pro", monospace;font-size:undefined; White-space:pre; border-radius:0px; Word-wrap:normal; " > <span class= "hljs-title" style= "Box-sizing:border-box; Color:rgb (0, 0, 136); >compile</span> <span class= "hljs-string" style= "Color:rgb (0, 136, 0); Box-sizing:border-box; " > ' Com.journeyapps:zxing-android-embedded:2.3.0<span class= ' hljs-variable "style=" Color:rgb (102, 0, 102); Box-sizing:border-box; " > @aar </span> ' </span> compile <span class= "hljs-string" style= "Color:rgb (0, 136, 0); Box-sizing:border-box; " > ' Com.journeyapps:zxing-android-legacy:2.3.0<span class= ' hljs-variable "style=" Color:rgb (102, 0, 102); Box-sizing:border-box; " > @aar </span> ' </span> compile <span class= "hljs-string" style= "Color:rgb (0, 136, 0); Box-sizing:border-box; " > ' COm.journeyapps:zxing-android-integration:2.3.0<span class= "hljs-variable" style= "Color:rgb" (102, 0, 102); Box-sizing:border-box; " > @aar </span> ' </span> compile <span class= "hljs-string" style= "Color:rgb (0, 136, 0); Box-sizing:border-box; " > ' com.google.zxing:core:3.2.0 ' </span></code><ul class= ' pre-numbering ' style= ' box-sizing: Border-box; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li><li style= "Box-sizing:border-box; padding:0px 5px; " >2</li><li style= "Box-sizing:border-box; padding:0px 5px; " >3</li><li style= "Box-sizing:border-box; padding:0px 5px; " >4</li></ul><ul class= "pre-numbering" style= "Box-sizing:border-box; Position:absolute; width:50px; Background-cOlor:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li><li style= "Box-sizing:border-box; padding:0px 5px; " >2</li><li style= "Box-sizing:border-box; padding:0px 5px; " >3</li><li style= "Box-sizing:border-box; padding:0px 5px; " >4</li></ul>

1.2 Call:

<code class= "HLJS cs has-numbering" style= "Display:block"; padding:0px; Background:transparent; Color:inherit; Box-sizing:border-box; font-family: "Source Code Pro", monospace;font-size:undefined; White-space:pre; border-radius:0px; Word-wrap:normal; " > Intentintegrator integrator=<span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); Box-sizing:border-box; " >new</span> intentintegrator (Mainactivity.<span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); box -sizing:border-box; "
    >this</span>); Integrator.initiatescan (); </code><ul class= "pre-numbering" style= "Box-sizing:border-box"; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li><li style= "Box-sizing:border-box; padding:0px 5px; " >2&lt/li></ul><ul class= "pre-numbering" style= "Box-sizing:border-box; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li><li style= "Box-sizing:border-box; padding:0px 5px; " >2</li></ul>

1.3 Callback Result:

<code class= "Hljs java has-numbering" style= "display:block; padding:0px; Background:transparent; Color:inherit; Box-sizing:border-box; font-family: "Source Code Pro", monospace;font-size:undefined; White-space:pre; border-radius:0px; Word-wrap:normal; " ><span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); Box-sizing:border-box; " >protected</span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >void</span> <span class= "Hljs-title" style= "Box-sizing:border-box;" >onActivityResult</span> (<span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); box-sizing:border-box; " >int</span> Requestcode, <span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); Box-sizing:border-box; " >int</span> ResultCode, Intent data) {<span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); Box-si Zing:border-box; "
        >super</span>.onactivityresult (Requestcode, ResultCode, data); INtentresult scanresult =intentintegrator.parseactivityresult (requestcode,resultcode,data); <span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); Box-sizing:border-box; " >if</span> (Scanresult!=<span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); box-sizing:border-box; "
            >null</span>) {String result=scanresult.getcontents (); Toast.maketext (<span class= "Hljs-keyword" style= "Color:rgb" (0, 0, 136); box-sizing:border-box; "
        >this</span>,result,toast.length_long). Show (); }}</code><ul class= "pre-numbering" style= "Box-sizing:border-box; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li><li style= "Box-sizing:border-box; padding:0px 5px; " >2</li><liStyle= "Box-sizing:border-box; padding:0px 5px; " >3</li><li style= "Box-sizing:border-box; padding:0px 5px; " >4</li><li style= "Box-sizing:border-box; padding:0px 5px; " >5</li><li style= "Box-sizing:border-box; padding:0px 5px; " >6</li><li style= "Box-sizing:border-box; padding:0px 5px; " >7</li><li style= "Box-sizing:border-box; padding:0px 5px; " >8</li></ul><ul class= "pre-numbering" style= "Box-sizing:border-box; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li><li style= "Box-sizing:border-box; padding:0px 5px; " >2</li><li style= "Box-sizing:border-box; padding:0px 5px; " >3</li><li style= "Box-sizing:border-box; padding:0px 5px; " >4</li>< Li style= "box-sizing:border-box; padding:0px 5px; " >5</li><li style= "Box-sizing:border-box; padding:0px 5px; " >6</li><li style= "Box-sizing:border-box; padding:0px 5px; " >7</li><li style= "Box-sizing:border-box; padding:0px 5px; " >8</li></ul>

Here you can see the scanning two-dimensional code interface and get the scan results, but this direct compile method, can not change the scanning interface is horizontal screen. 2. Change module to library and modify it to vertical screen

2.1 GitHub Download Good zxing source code. Https://github.com/zxing/zxing
Import the Android project in the source code

Modified in Build.gradle

Modify in Manifest (Captureactivity is the class to invoke)

2.2 Problem 1 Constant expression error
After modifying the build file, we reported a constant expression error and found that it was in each switch statement that Alt+enter changed the switch case statement to if else.
Reason: Avoid resource conflicts between multiple libraries (refer to them specifically)

Question 2 manifest problem
Because we are to change a module directly into the library, so to delete the same attributes, similar to Android:icon,andoid:label,intentfileter, etc. to be deleted.
2.3 Reference in your own project

<code class= "Hljs scss has-numbering" style= "Display:block"; padding:0px; Background:transparent; Color:inherit; Box-sizing:border-box; font-family: "Source Code Pro", monospace;font-size:undefined; White-space:pre; border-radius:0px; Word-wrap:normal; " >compile <span class= "hljs-function" style= "Box-sizing:border-box"; >project (<span class= "hljs-string" style= "Color:rgb" (0, 136, 0); box-sizing:border-box; " > ': Android ' </span> </span></code><ul class= ' pre-numbering ' style= ' box-sizing:border-box; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; margin:0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li></ul><ul class= "pre-numbering" style= "Box-sizing:border-box; Position:absolute; width:50px; Background-color:rgb (238, 238, 238); top:0px; left:0px; Margin: 0px; padding:6px 0px 40px; BORDER-RIGHT:1PX Solid RGB (221, 221, 221); List-style:none; Text-align:right; " ><li style= "Box-sizing:border-box; padding:0px 5px; " >1</li></ul>

Each view of the scan interface can be modified in captureactivity.

Call result

Experience: These days in order to get this, really go through the wall outside, every day is in torment, sometimes really want to have a great God guidance is good, minutes can solve these problems.
Well, it's up to you, come on.

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.