Android 将二维码扫描仪与Zxing集成时出错

Android 将二维码扫描仪与Zxing集成时出错,android,qr-code,Android,Qr Code,我正在尝试将二维码扫描仪集成到我的android应用程序中。我采取了以下步骤: 我已经下载了ZXing.zip文件并将其解压缩 将ZXing项目作为android现有项目打开,然后转到android文件夹,打开android文件夹,并将core.jar文件包含到名为CaptureActivity的ZXing项目中 我在名为“QRCodeSample”的项目中将CaptureActivity项目用作库 这是我的MainActivity.java文件: package com.charith.qrc

我正在尝试将二维码扫描仪集成到我的android应用程序中。我采取了以下步骤:

  • 我已经下载了ZXing.zip文件并将其解压缩

  • 将ZXing项目作为android现有项目打开,然后转到android文件夹,打开android文件夹,并将core.jar文件包含到名为CaptureActivity的ZXing项目中

  • 我在名为“QRCodeSample”的项目中将CaptureActivity项目用作库

  • 这是我的MainActivity.java文件:

    package com.charith.qrcodesample;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    
        Button b1;
        TextView scanResult;
        String contents;
        public static final int REQUEST_CODDE = 1;
        protected static final String QR_CODE_MODE = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            b1 = (Button) findViewById(R.id.bScan);
            b1.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    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) {
            scanResult = (TextView) findViewById(R.id.tvContent);
            if(requestCode == 0) {
                if(resultCode == RESULT_OK) {
                    contents = intent.getStringExtra("SCAN_RESULT");
                    String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                    scanResult.setText(contents);
                }else if(resultCode == RESULT_CANCELED){
                    scanResult.setText("Error");
                }
            }
        }
    
    }
    
    这是我的AndroidManifest.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.charith.qrcodesample"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="10"
            android:targetSdkVersion="10" />
    
        <uses-permission android:name="android.permission.CAMERA" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <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>
                <intent-filter>
                    <action android:name="com.google.zxing.client.android.SCAN" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.charith.qrcodesample.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
    
        <Button
            android:id="@+id/bScan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="33dp"
            android:text="Scan" />
    
        <TextView
            android:id="@+id/tvContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/bScan"
            android:layout_below="@+id/bScan"
            android:layout_marginTop="44dp"
            android:text="" />
    
    </RelativeLayout>
    

    如果有人能尽快澄清这个问题,我们将不胜感激。

    首先,您已经复制并粘贴了我们的项目。我想你也复制了用户界面。正如您在这里的许多问题中看到的,以及在中讨论的,这是开源许可证不允许的

    其次,您复制并粘贴了
    AndroidManifest.xml
    声明。您正在我们的命名空间中声明一个
    活动
    ,并拦截我们的
    意图
    s。这将干扰我们的应用程序,不正常。删除此项并创建自己的清单


    但第三,您似乎试图通过
    意图集成。这比这容易得多,而且与错误地复制和粘贴所有这些内容无关。请参见

    Eclipse中的Android emulator不支持摄像头。是否有可能因为缺少摄像头支持,模拟器无法工作?在将此错误归为代码错误之前,我会在运行的Android设备上测试此应用程序;很可能这只是一个与Android Emulator/Eclipse相关的问题。Thanx Sean。我尝试过这样做,但没有效果。事实上这不是很清楚,因为我是Android新手。如果你能一步一步地解释,我将非常感激。Thanx再次感谢你的回复。你尝试过什么?没有什么可以解释的。添加jar文件并使用该wiki上的代码。
    The application has stopped unexpectedly. Please try again