Vivendi
Vivendi

Reputation: 21057

Integrate ZXing without the use of a 3rd party scanner?

I've read numerous topics already where people asked how to integrate ZXing in an Android application where they necessarily need to have a 3rd party scanner app installed in order to scan a QR Code.

That's exactly what i want to do too. This is what i have done so far:

I downloaded the ZXing project. I copied all the relevant source code to my Android application. So far so good, it all compiles fine. When i press on a button in my app it opens a small dialog asking what barcode scanner i want to use. I have the following options:

  1. QR-Droid (3rd party app)
  2. My own app

When i use the first option, then the camera gets activated and i can scan a QR code. But when i use the 2nd option (my own app), then nothing happends. I thought ZXing came with a scanner too, so that a 3rd party QR scanner isn't necessary??

But maybe there are other steps i have to take aswell? This is how my manifest looks like:

Added this:

<intent-filter>
    <action android:name="com.google.zxing.client.android.SCAN"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

And in a button action i have:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");         
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");  
startActivityForResult(intent, 0);

Is there any way to make a QR Scanner start without the need of a 3rd party scanner?? I have all the source imported in my project.

Upvotes: 0

Views: 2696

Answers (2)

Sean Owen
Sean Owen

Reputation: 66886

This is confused, and the approach you have accepted is harmful.

First, please do not copy our app wholesale, as we have repeatedly stressed here. It is not only discouraged, but violates our trademark if you clone the UI. Just don't do it.

Second, you are copying our code, but then are trying to use a scanner by Intent. Why? If you want to use Intents, you don't need to use any code.

Third, you are declaring your app to respond to our app Intent. You are intercepting calls intended for Barcode Scanner. If you can reply in exactly the same way, OK, but, I imagine you are not guaranteeing this. By doing so you're harming users of Barcode Scanner, the open source project you're profiting from.

Upvotes: 3

Vivek Kumar Srivastava
Vivek Kumar Srivastava

Reputation: 2158

Modify your Manifest and add this

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

also add camera permission

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

and implemetn onActivityResult method in your Activity

 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");
                Log.i("xZing", "contents: "+contents+" format: "+format);
                // Handle successful scan
            } 
            else if (resultCode == RESULT_CANCELED)
            {
                // Handle cancel
            }
        }
    }

for more information or any trouble see this link

Upvotes: 2

Related Questions