我从这个网站了解到: http: //damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
我在集成 Zxing 时遇到了两个小问题:
- 我的应用程序名称现在是“条形码扫描仪”
- 当我想使用集成条形码扫描仪时出现此错误:
java.lang.ClassNotFoundException : android.preference.set
但是,当我选择使用条形码扫描仪(以前安装在我的智能手机上)时,没有错误!你有什么想法吗?
我的代码是:
显现 :
<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>
活动 :
/* -- 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");
}
}
}
/*----------------------------------*/
项目“CaptureActivity”被设置为库,并包含在我的项目中。core.jar 也作为“外部 JAR”包含在内。