整合ZXing QR code扫描,而无需安装吧code扫描仪 [英] Integrate ZXing QR code scanner without installing BarCode Scanner
问题描述
我试图整合ZXing QR code到我的Android应用程序,而无需安装吧code扫描仪的应用程序,我按照步骤如下:
I am trying to Integrate ZXing QR Code into my android app without installing BarCode Scanner app, I have followed the steps as:
1)首先,我已经下载ZXing.zip文件,解压
1) Firstly I have downloaded ZXing.zip file and extract it
2)打开ZXing项目作为一个机器人现有的项目,然后去到Android文件夹,打开Android的文件夹,还包括core.jar添加文件到名为CaptureActivity的ZXing项目。
2)open the ZXing project as an android existing project and then go to android folder and open the android folder and also include core.jar file into the ZXing project named CaptureActivity.
3)我已经使用了CaptureActivity项目作为我的项目库名为QR codeSAMPLE。 (在包括CaptureActivity为库问题)
3)I have used the CaptureActivity project as a library in my project named 'QRCodeSample'. (Problem in including CaptureActivity as a library)
4)我的code是为below3:
4)My code is as below3:
public class QRCodeSampleActivity extends Activity {
Button b1;
static String contents;
public static final int REQUEST_CODE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
/*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);*/
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i("Barcode Result", contents);
Intent i1 = new Intent(QRCodeSampleActivity.this, webclass.class);
startActivity(i1);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("Barcode Result","Result canceled");
}
}
}
}
清单文件是:
The manifest file is :
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<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>
<activity
android:label="@string/app_name"
android:name=".QRCodeSampleActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".webclass"></activity>
</application>
</manifest>
和它不添加库还
当我试图运行我的项目,该错误味精是:
When I am trying to run my project,the error msg is:
无法实例活动ComponentInfo {com.qr. code / com.qr. code}:抛出java.lang.ClassNotFoundException:装载机dalvik.system.PathClassLoader com.qr. code [ /data/app/com.qr.$c$c-1.apk]
Unable to instantiate activity ComponentInfo{com.qr.code/com.qr.code}: java.lang.ClassNotFoundException: com.qr.code in loader dalvik.system.PathClassLoader[/data/app/com.qr.code-1.apk]
推荐答案
最后,我得到了答案,
作为ADT 14,资源领域(如R.id.de code)不再常数,当库项目定义
所以在ZXing库 - > android-> com.google.zxing.client.android.CaptureActivityHandler.java和德codeHandler.java
So in the ZXing library->android->com.google.zxing.client.android.CaptureActivityHandler.java and DecodeHandler.java
替换这两个类开关case语句与if-else语句,然后这ZXing库导入到项目中。
Replace both of these classes switch case statements with if-else,and then import this ZXing library into your project..
我自己的项目编码的休息是一样的...只是问题的库类,因为它们不更新,根据ADT 14 ..
Rest of the coding of my own project is same...just the problem with the library classes as these are not updated as according to ADT 14..
堪
这篇关于整合ZXing QR code扫描,而无需安装吧code扫描仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!