Getting started with ZXing on Android

后端 未结 8 756
野性不改
野性不改 2021-01-06 12:05

I\'m trying to add ZXing to my project (add a button which calls the scanner upon press). I found this: http://groups.google.com/group/android-developers/browse_thread/threa

相关标签:
8条回答
  • 2021-01-06 12:22

    I use Zxing in a tab (a Fragment) and use the support library (for Material Design components) so I had to call it like this:

    IntentIntegrator integrator = new IntentIntegrator(getActivity()); integrator.forSupportFragment(this).initiateScan();

    then in onActivityResult()

        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == IntentIntegrator.REQUEST_CODE) {
    
                String contents = data.getStringExtra("SCAN_RESULT");
                String format = data.getStringExtra("SCAN_RESULT_FORMAT");
                Log.i(TAG, "Barcode Result: " + contents);
                etc...
            }
        }
    

    and in my Manifest.xml

        <activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            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>
    

    It all works very nicely now. I was not successful just using intents and startActivityForResult(). The scanner would start and fix on the QRcode but did not return.

    In my build.grade, I have:

    repositories { mavenCentral() maven { url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/" } }

    compile 'com.google.zxing:core:3.2.1'
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
    
    0 讨论(0)
  • 2021-01-06 12:24

    barcode scanner application is not installed on your emulator which is giving this exception.Below link gives step by step guide how to install the 3rd party application on the emulator:

    Install application on emulator

    0 讨论(0)
  • 2021-01-06 12:26

    Go here for links.

    In the activity that you want to trigger a barcode scan include

    IntentIntegrator.initiateScan(YourActivity.this); 
    

    and then also include:

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                // Handle successful scan
                TextView 
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    };
    

    The Barcode Scanner app will handle the actual scanning. If the Barcode Scanner app is not installed, the integrator will prompt them to install it.

    ----------- From nEx.Software ---------------

    0 讨论(0)
  • 2021-01-06 12:27

    if you use the zxing first time,I recommend this project*1*,it's a part of zxing, all you need is import the project and run it.This project is an attempt to make working with QR codes in Android a bit easier. With strongly recommend to bigenner.good luck. At last,thanks Sean Owen;

    0 讨论(0)
  • 2021-01-06 12:41

    Just add this code to your manifest file, within the application tag:

     <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.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    

    Then add the following permission, if it has not already been added, at the top of file:

    <uses-permission android:name="android.permission.CAMERA" />
    

    0 讨论(0)
  • 2021-01-06 12:43

    First, ZXing will not be able to automatically prompt the user to download from the Market on an emulator, because there is no Market on the emulator. You would need to manually install the Barcode Scanner APK on the emulator.

    Second, since the emulator does not emulate a camera, Barcode Scanner probably will not do you much good. Most likely you are going to need to test this out on a device.

    0 讨论(0)
提交回复
热议问题