使用Android的Zxing酒吧code扫描仪 [英] Android Barcode scanner using Zxing

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

问题描述

我要Zxing在Android项目(我是初学者)。

集成

我已经看到,这里所描述的方式 http://bit.ly/nBszrL 气馁,而且做到这一点最好的办法是通过如意图在这个岗​​位 http://bit.ly/o29Uma

P.S:我不希望在栏code扫描仪安装在我的设备上

我已经包括在我的项目所需的类: http://bit.ly/16pKMKx


  

我的测试code:


 包com.example.bar codescanner;进口android.os.Bundle;
进口android.app.Activity;
进口android.content.Intent;
进口android.view.Menu;
进口android.view.View;
进口android.widget.Button;
进口android.widget.Toast;公共类MainActivity延伸活动{    私有静态最终诠释REQUEST_BAR code = 0;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }    //当我的按钮被点击
    公共无效scanBar code(查看视图){
        意向意图=新意图(com.google.zxing.client.android.SCAN);
        intent.putExtra(SCAN_MODE,PRODUCT_MODE);        startActivityForResult(意向,REQUEST_BAR code);        吐司面包= Toast.makeText(这一点,开始扫描吧code,Toast.LENGTH_SHORT);
        toast.show();
    }}

和我真的不明白如何通过这种方式来做到这一点: http://bit.ly/18v7K2O(我真的不明白这一点,这就是我想用什么)

你有关于如何做到这一点任何想法?

感谢您。


解决方案

Android系统的建立是为了让人们可以写做一件事特别好,当他们需要其他开发者可以使用他们的应用程序。酒吧code扫描是一个很好的例子。 ZXing使一个伟大的扫描仪,并让其他应用通过意图使用它。基本上你告诉操作系统要扫描棒code和ZXing说,是的,我能做到这一点!他们扫描了吧code和信息返回给你。关于做这种方式的好处是,你不必担心,当他们更新自己的东西。用户只需得到通知,它的更新,你会得到使用最新和最伟大。一个潜在的缺点是,用户在手机上的其他应用程序,但我真的不认为这是一个平局回来。要做到这种方式,你真的只需要您链接到这两个文件,​​然后你只需将这个在code要开始扫描:

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

和该位从酒吧code扫描仪得到了答案:

 公共无效的onActivityResult(INT申请code,INT结果code,意图意图){
    IntentResult scanResult = IntentIntegrator.parseActivityResult(要求code,结果code,意向);
    如果(scanResult!= NULL){
        //处理扫描结果
    }
    //否则继续与其他任何code你的方法需要
  ...
}

您唯一的选择就是拉了所有的code为酒吧code扫描仪和块状的到您的项目,然后弄清楚它是如何工作以及你需要配合把它为您的应用程序。然后,你必须每ZXing使得更新时间做一遍。这是一个烂摊子!

I want to integrate Zxing in a android project (I'm a beginner).

I have seen that the way described here http://bit.ly/nBszrL is discouraged and that the best way to do it is through Intents as said in this post http://bit.ly/o29Uma

p.s : I don't want the barcode scanner installed on my device

I have Included on my project the required class : http://bit.ly/16pKMKx

my test code :

package com.example.barcodescanner;

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

public class MainActivity extends Activity {

    private static final int REQUEST_BARCODE = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    // when my button is clicked
    public void scanBarCode(View view) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "PRODUCT_MODE");  

        startActivityForResult(intent, REQUEST_BARCODE);

        Toast toast = Toast.makeText(this, "Start scanning Barcode", Toast.LENGTH_SHORT);
        toast.show();
    }

}

and I really don't understand how to do it by this way : http://bit.ly/18v7K2O (I really don't get it and that's what I want to use)

Do you have any idea about how to do it ?

Thank you.

解决方案

The Android system was built to so that people could write apps that do one particular thing well and other developers could use them when they need to. Barcode scanning is a great example. ZXing makes a great scanner and lets other apps use it via Intents. Basically you tell the OS that you want to scan a barcode and ZXing says, "Yes, I can do that!" They scan the barcode and return the information to you. The great thing about doing it this way is that you don't have to worry about when they update their stuff. The user just gets notified that it's updated and you get to use the latest and greatest. The one potential downside is that the user has another app on their phone but I don't really see that as a draw back. To do it this way you really only need the two files you linked to and then you just place this in your code To start the scan:

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

And this bit gets the answer from the barcode scanner:

public 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
  ...
}

Your only other option is to pull down all of the code for the barcode scanner and lump that into your project and then figure out how it all works and where you need to tie in to bring it into your app. Then you'll have to do that all over again every time ZXing makes an update. It's a mess!

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

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