Including ZXing into an app as a library

614 views
Skip to first unread message

Brice Corum

unread,
Sep 26, 2011, 10:51:59 AM9/26/11
to zxing
I have created a ZXing Library using the android source and a core.jar
file. I am using phonegap plugin to build my UI which includes a
button that calls a scan method located in com.beetight.barcodescanner
that calls

startActivityForResult(new Intent(this.ctx, CaptureActivity.class),
RESULT_CODE);

scan method from com.beetight.barcodescanner.BarcodeScanner.java

public void scan(String barcodeFormats, String installTitle, String
installMessage, String yesString, String noString ) {
/*
Intent intentScan = new
Intent("com.google.zxing.client.android.SCAN");
intentScan.addCategory(Intent.CATEGORY_DEFAULT);

// A null format means we scan for any type
if (barcodeFormats != null) {
// Tell the scanner what types we're after
intentScan.putExtra("SCAN_FORMATS", barcodeFormats);
}

intentScan.putExtra("SCAN_WIDTH", 600); // need to change to
device width
intentScan.putExtra("SCAN_HEIGHT", 150);

try {
this.ctx.startActivityForResult((Plugin) this, intentScan,
REQUEST_CODE);
} catch (ActivityNotFoundException e) {
showDownloadDialog(installTitle, installMessage, yesString,
noString);
}
/*/

this.ctx.startActivityForResult(new Intent(this.ctx,
CaptureActivity.class), REQUEST_CODE);
}

When I try to run I get the error message

Scanning Failed : Unable to find explicit activity class
{com.phonegap.barcodescanner/com.google.zxing.client.CaptureActivity};
Have you declared this activity in your AndroidManifest.xml

My AndroidManifest.xml looks like

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.phonegap.barcodescanner"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.RECEIVE_SMS" />
<uses-permission
android:name="android.permission.RECORD_AUDIO" />
<uses-permission
android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission
android:name="android.permission.READ_CONTACTS" />
<uses-permission
android:name="android.permission.WRITE_CONTACTS" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".BarcodeScannerActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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="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>

</application>
</manifest>


Any ideas to what I am doing wrong?

Lachezar Dobrev

unread,
Sep 26, 2011, 11:26:10 AM9/26/11
to Brice Corum, zxing
Don't try to include ZXing Barcode Scanner in your application.
The whole permissions + Capture Activity stuff has no place in your
application. This method relies on having the Barcode Scanner
installed on the same device.

1. Remove any trace of the ZXing source code from your application.
2. Install Barcode Scanner on the Android device.
3. The PhoneGap plug-in does the magic.

2011/9/26 Brice Corum <br...@waynereaves.com>:

Brice Corum

unread,
Sep 26, 2011, 11:40:55 AM9/26/11
to zxing
Figured it out. Thanks anyways.
Reply all
Reply to author
Forward
0 new messages