在Android上使用"Zxing的条码扫描器"应用程序

Mar*_*mix 0 android zxing google-play

我正在修改现有的应用程序.该应用程序通过Java类和包使用"Zxing的条形码扫描仪".

我的项目包括那些包:

com.google.zxing com.google.zxing.integration com.google.zxing.integration.android

我有一个类,有一些像这样的代码:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class QRdecoderActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // temp = this;

        IntentIntegrator.initiateScan(this);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch(requestCode) {

            case IntentIntegrator.REQUEST_CODE: {

                if (resultCode != RESULT_CANCELED) {

                    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

                    if (scanResult != null) {
                        String upc = scanResult.getContents();

                        Toast.makeText(this, "Contents : " + upc, Toast.LENGTH_LONG).show();

                    }

                }
                finish();               

                break;
            }
        }
    }   
}
Run Code Online (Sandbox Code Playgroud)

一切都很好,但是当我开始测试过程时,我发现我需要安装"条码扫描器"应用程序.

这是对的吗?

如果它在我的项目中使用Java类,我认为我不需要.

我如何检查应用程序是否已安装?我如何进入"Google Play"并从我的代码下载到用户?

Gra*_*ith 5

这已在之前讨论过,并且在Zxing网站上有很好的文档记录.虽然您可以将源集成到您的应用程序中,但您也可以通过意图进行扫描.

根据您发布的内容,看起来源代码已经集成到应用程序中,因此您不需要安装它(因为所有类都应该在那里).

如果系统提示您安装条形码扫描仪应用程序,则听起来似乎正在使用意图扫描.最终的结果是你有两种方法的混合,其中通过意图扫描是使用的方法.

我个人更喜欢通过意图进行扫描.这在此处记录:http://code.google.com/p/zxing/wiki/ScanningViaIntent.

我的理由是你的应用程序独立于条形码扫描器.由新条形码标准或一般错误修复/改进引起的任何更新都会立即提供给最终用户(作为Google Play的更新),因为他们无需等待您的应用集成任何更新的源代码.此外,如果您打算为Zxing添加价值,我们鼓励您只使用Zxing的来源.

我如何检查应用程序是否已安装?我如何进入"Google Play"并从我的代码下载到用户?

Zxing提供的类可以优雅地处理用户发出意图并且未安装Barcode Scanner应用程序的情况.它会将用户直接带到Google Play上的应用.您可以在http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java找到它.

完成课程后,您只需要拨打以下电话:

IntentIntegrator integrator = new IntentIntegrator(yourActivity);
integrator.initiateScan();
Run Code Online (Sandbox Code Playgroud)

然后添加到您的活动中

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
  ...
}
Run Code Online (Sandbox Code Playgroud)