Onuray Sahin
Onuray Sahin

Reputation: 4135

How to integrate Zxing without installing barcode scanner application?

I added Zying android application to my application as library. Then edited Manifest.xml and tried to use Intent integrator. No luck.

Downloading scanner app is totally unreasonable.

By the way:

Intent scanIntent = new Intent("com.google.zxing.client.android.SCAN");
scanIntent.setPackage("com.google.zxing.client.android");

11-11 15:15:27.793: WARN/System.err(15384): android.content.ActivityNotFoundException: No 
Activity found to handle Intent { act=com.google.zxing.client.android.SCAN 
cat=[android.intent.category.DEFAULT] pkg=com.google.zxing.client.android (has extras) }

Upvotes: 13

Views: 15175

Answers (3)

Piyush
Piyush

Reputation: 2050

You need to follow step as given by the link

http://www.androidaz.com/development/zxing-qr-reader-direct-integration

you can download core.jar from

http://repo1.maven.org/maven2/com/google/zxing/core/2.2/

The above is working for me, if you get error just put the core-2.2.jar in libs and clean your project

Upvotes: 0

devunwired
devunwired

Reputation: 63303

You are trying to access the ZXing scanner in two directly conflicting ways. The purpose of the IntentIntegrator that ZXing provides is to make accessing the external scanner app simpler by building the Intent for you with all the appropriate constants and flags. If you do not want to install and run the external scanner app from Android Market on a device, IntentIntegrator is not for you. This is also true wit the Java code you posted, as it is essentially the same Intent the integrator would create to launch the external application.

If you integrate ZXing into your project as a library, then the components become a part of your application and they must be referenced as such. For example, a declaration in AndroidManifest.xml needs to be added such as:

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

Make sure you used the correct name here for the activity and action, as these have to reference the library. Then you can launch the scanner Activity from your Java code using the following:

int REQUEST_SCAN; //Request code for Intent result
String packageString = "com.yourapplication.packagename";

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage(packageString);
//Add any optional extras to pass
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
//Launch
startActivityForResult(intent, REQUEST_SCAN);

Notice the Intent action matches the declaration in the manifest, but the PACKAGE is this application, not the Android Market ZXing application.

HTH

Upvotes: 15

Vineet Shukla
Vineet Shukla

Reputation: 24031

+1 for your question. I tried this but no luck then I added it's code files in my app. If you wish you can also do that. Here ia a link:

http://code.google.com/p/zxing/source/browse/trunk#trunk%2Fandroid

If you get any better way then let me know.

Upvotes: 3

Related Questions