酒吧code图像扫描仪 [英] Barcode image Scanner

查看:136
本文介绍了酒吧code图像扫描仪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我试图建立一个吧code扫描仪的作品如下: 通过相机拍摄的图像(条码code)和扫描这条code图像。 我的问题是,我该怎么办呢? 在此先感谢

下面是我的code:

  TextView的result_text;
按钮scan_btn;

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    result_text =(TextView中)findViewById(R.id.Result_tv);

    scan_btn =(按钮)findViewById(R.id.Bar code_Scan_Button);
    scan_btn.setOnClickListener(新View.OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            意图scanIntent =新的意向书(com.google.zxing.client.android.SCAN);
            scanIntent.putExtra(SCAN_MODE,QR_ code_MODE);

            startActivityForResult(scanIntent,0);

        }
    });
}

公共无效onActivityResult(INT申请code,INT结果code,意图意图){

        如果(要求code == 0){


          如果(结果code == RESULT_OK){

            result_text.setText(intent.getStringExtra(SCAN_RESULT));

          }否则,如果(结果code == RESULT_CANCELED){

            result_text.setText(扫描取消。);

          }

        }

      }

    }
 

解决方案

@Zain你正在服用的方法是严格不建议

按照他们的指引,你不应该显式调用扫描意向。

您必须使用zxing发布了新的 IntentIntegrator 类。

在这里你去

首先增加code调用的意图:

  IntentIntegrator积分=新IntentIntegrator(yourActivity);
integrator.initiateScan();
 

下载IntentIntegrator从以下网址类。

<一个href="http://$c$c.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java" rel="nofollow">http://$c$c.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java

二,添加到您的活动,以处理结果:

  @覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图意图){
  IntentResult scanResult = IntentIntegrator.parseActivityResult(要求code,因此code,意图);
  如果(scanResult!= NULL){
    //处理扫描结果
  }
  //否则继续与其他任何code,你需要在方法
  ...
}
 

投资你的时间去通过Zxing.They的维基页面已经解释得很好听。

HTTP://$c$c.google.com/p/ zxing / W /列表

HTTP://$c$c.google.com/p/ zxing /维基/ ScanningViaIntent

下面是示例应用程序演示如何调用Zxing意图。

<一个href="http://$c$c.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java" rel="nofollow">http://$c$c.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java

最后测试项目+图书馆位于

<一个href="http://$c$c.google.com/p/zxing/source/browse/trunk#trunk/android-integration%253Fstate%253Dclosed" rel="nofollow">http://$c$c.google.com/p/zxing/source/browse/trunk#trunk%2Fandroid-integration%253Fstate%253Dclosed

I am new to android. I am trying to develop a barcode scanner, that works as follow: Take image(of barcode) via camera and scan this barcode image. my question is how i can do it? Thanks in advance

Here is my code:

TextView result_text;
Button scan_btn;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    result_text = (TextView)findViewById(R.id.Result_tv);

    scan_btn = (Button)findViewById(R.id.Barcode_Scan_Button);
    scan_btn.setOnClickListener( new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent scanIntent= new Intent("com.google.zxing.client.android.SCAN");
            scanIntent.putExtra("SCAN_MODE", "QR_CODE_MODE");

            startActivityForResult(scanIntent, 0);

        }
    });
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {

        if (requestCode == 0) {


          if (resultCode == RESULT_OK) {

            result_text.setText(intent.getStringExtra("SCAN_RESULT"));

          } else if (resultCode == RESULT_CANCELED) {

            result_text.setText("Scan cancelled.");

          }

        }

      }

    }

解决方案

@Zain the approach you are taking is strictly not recommended.

As per their guidelines you should not explicitly call Scan Intent.

You must used new IntentIntegrator class released by zxing.

Here you go

First add code to invoke the Intent:

IntentIntegrator integrator = new IntentIntegrator(yourActivity);
integrator.initiateScan();

Download IntentIntegrator class from below url.

http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java

Second, add this to your Activity to handle the result:

@Override   
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
  if (scanResult != null) {
    // handle scan result
  }
  // else continue with any other code you need in the method
  ...
}

Invest your time to go through wiki page of Zxing.They have explained it very nicely.

http://code.google.com/p/zxing/w/list

http://code.google.com/p/zxing/wiki/ScanningViaIntent

Here is sample application demonstrating how to call Zxing intent.

http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java

Finally Test Project + Library is located at

http://code.google.com/p/zxing/source/browse/trunk#trunk%2Fandroid-integration%253Fstate%253Dclosed

这篇关于酒吧code图像扫描仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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