集成ZXing二维码扫描器,无需安装BarCode Scanner [英] Integrate ZXing QR code scanner without installing BarCode Scanner

查看:44
本文介绍了集成ZXing二维码扫描器,无需安装BarCode Scanner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 ZXing QR Code 集成到我的 android 应用程序中而不安装 BarCode Scanner 应用程序,我已按照以下步骤操作:

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文件夹,打开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) 我在名为QRCodeSample"的项目中使用了 CaptureActivity 项目作为库.(将 CaptureActivity 作为库包含的问题)

3)I have used the CaptureActivity project as a library in my project named 'QRCodeSample'. (Problem in including CaptureActivity as a library)

4)我的代码如下3:

   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");
        }
    }
}

 }

清单文件是:

<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:

无法实例化活动组件信息{com.qr.code/com.qr.code}:java.lang.ClassNotFoundException:加载器dalvik.system.PathClassLoader中的com.qr.code[/data/app/com.qr.代码-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.decode)在库项目中定义时不再是常量

所以在ZXing库->android->com.google.zxing.client.android.CaptureActivityHandler.java和DecodeHandler.java

So in the ZXing library->android->com.google.zxing.client.android.CaptureActivityHandler.java and DecodeHandler.java

用 if-else 替换这两个类的 switch case 语句,然后将这个 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二维码扫描器,无需安装BarCode Scanner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆