Android uses zxing2.1 to read the QR code

Source: Internet
Author: User

[Thanks for reference]: http://mukeshyadav4u.blogspot.com/2012/06/integrating-zxing-qr-code-scanner-into.html

Using the connection method, I found that no result is returned after the reading is successful, and then I checked the source code. The reason is that captureactivity is forwarded based on the source, set the source action in intent.

Main process:

1. Download zxing source code

Use SVN checkoutHTTP: // Zxing.googlecode.com/svn/trunk/ source code

2. Import the android project to eclipse and mark it as libproject

3. Create your own project and apply libprpoject in Section 2

4. Add the following content to your androidmanifest. xml file:

 <activity            android:name="com.google.zxing.client.android.CaptureActivity"            android:configChanges="orientation|keyboardHidden"            android:screenOrientation="landscape"            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"            android:windowSoftInputMode="stateAlwaysHidden" >           <!--  <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter> -->            <intent-filter>                <action android:name="com.google.zxing.client.android.SCAN" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>        </activity>

5. Call the service to read the QR code

I used a button for demonstration.

public void scan(View view){Intent intent = new Intent(this,CaptureActivity.class);intent.setAction(Intents.Scan.ACTION);intent.putExtra(Intents.Scan.MODE, Intents.Scan.QR_CODE_MODE);intent.putExtra(Intents.Scan.RESULT_DISPLAY_DURATION_MS, 0L);startActivityForResult(intent, 0);}

6. In COM. bbcvison. zxing. test. mainactivity. onactivityresult is used to process the QR code. For the key value of the result of reading the card, see COM. google. zxing. client. android. intents. scan
Attachment: captureactivity.rar is the libprojectcaptureactivitytest.rar generated by me. Thanks again: Thanks again

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.