【问题标题】:Why Zxing barcode result always error为什么Zxing条码结果总是出错
【发布时间】:2011-12-09 07:51:19
【问题描述】:

我是一名初级 Android 开发人员。近 4 天以来,我尝试使用自己的应用程序制作 ZXing 条码,但结果始终为零。我终于找到了一个教程,解释了如何通过意图连接到 ZXing。它编译得很好,但应用程序在扫描条形码后总是导致错误。

这是我的代码:

// java file --------------

package zxing.src;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class zxing_act extends Activity {
    /** Called when the activity is first created. */
        private EditText edittext1, editText2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        EditText edittext1 = (EditText) findViewById(R.id.edittext1);
        EditText editText2 = (EditText) findViewById(R.id.editText2);

        Button next = (Button) findViewById(R.id.button1);
        next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            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) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            edittext1.setText(contents);
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            editText2.setText(format);             
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
      }
   }
}

// manifest file --------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="zxing.src"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:name=".zxing_act" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.zxing.client.android.ROBOTICEYEOMG"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
</application>

</manifest>

// layout file ----------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
       android:id="@+id/edittext1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" >

    <requestFocus />
    </EditText>

    <EditText
       android:id="@+id/editText2"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />


   <Button
      android:id="@+id/button1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Button" />

</LinearLayout>

我想知道我的错误在哪里。非常感谢您的帮助。

【问题讨论】:

  • 如果您从 logcat 发布消息会很有帮助。
  • 就是这样,请发布logcat
  • 请不要在代码中复制我们的项目名称和包。
  • 大家好,我的问题终于得到解答。 thnks 4所有。 @ sean 和集成团队:我非常感谢您的所有努力,我只是将您的项目添加到应用程序的构建路径中,但我没有更改。

标签: android barcode zxing


【解决方案1】:

您尚未指定错误是什么,但是,我可以建议在项目中使用android-integration 中提供的IntentIntegrator 类,而不是尝试编写自己的集成代码。

【讨论】:

  • 嗨,肖恩,这是来自 IntentIntegrator 的精彩代码。我成功地运行我的代码而没有错误并得到结果。感谢您编写该代码。 :)
【解决方案2】:

尝试更改清单文件

<intent-filter>
    <action android:name="com.google.zxing.client.android.ROBOTICEYEOMG"/>
    <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>

【讨论】:

  • 感谢您的建议,但结果保持不变。顺便说一句,我在安装条形码扫描仪应用程序的情况下使用此程序。
  • 不,他不想听他的意图。他需要发送意图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多