Reputation: 1903
I've learned from this website : http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
I've got two little problems with integration of Zxing :
java.lang.ClassNotFoundException : android.preference.set
But, when I choose to use the barcode scanner (previously installed on my smartphone), there are no errors ! Have you got any idea ?
My code is :
Manifest :
<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>
</activity>
Activity :
/* -- LISTENER CLICK SCAN PRODUCT -- */
View.OnClickListener bScanProduct = new View.OnClickListener() {
public void onClick(View v) {
LayoutInflater inflater = getLayoutInflater();
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}
};
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.w("SuggestionActivity", "Scan receved : "+contents+" format : "+format);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.w("SuggestionActivity", "Cancel scan");
}
}
}
/*----------------------------------*/
The project "CaptureActivity" is set as library, and include in my project. And the core.jar is also include as an "External JAR".
Upvotes: 0
Views: 1352
Reputation: 66866
Don't follow this blog post. It is showing you how to copy and paste our app, which is strongly discouraged, for a reason you are highlighting right here. Intentionally or not, people create clone apps that use the same icon, name, and Manifest settings, which interfere with apps integrating with the real Barcode Scanner by Intent.
Reusing parts of the code in your own app is OK, if you know what you are doing, but if you are surprised by the name thing, I doubt this is the case.
In fact, in your edit, you show you are trying to integrate by Intent
. This is far easier and requires none of the core/
or android/
code.
Correct integration instructions are found in the project itself: http://code.google.com/p/zxing/wiki/ScanningViaIntent
Please integrate this way if you are not sure enough about how this works to responsibly reuse the source code of Barcode Scanner.
Upvotes: 1