development

ZXing을 사용하여 Android 바코드 스캔 앱 만들기

big-blog 2020. 5. 30. 09:53
반응형

ZXing을 사용하여 Android 바코드 스캔 앱 만들기


이 질문에는 이미 답변이 있습니다.

앱에 바코드 스캐너를 추가하는 방법을 찾고있었습니다. 예가 있습니까? 아니면 어떻게 쉽게 할 수 있습니까?


ZXing 프로젝트는 Android의 의도 메커니즘을 통해 바코드 스캐닝을 통합하려는 다른 애플리케이션에서 호출 할 수있는 독립형 바코드 리더 애플리케이션을 제공합니다.가장 쉬운 방법은 다음 과 같이

SCAN Intent

응용 프로그램 에서 ZXing을 호출하는

것입니다

.

public Button.OnClickListener mScan = new Button.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");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

연결된 버튼을 누르면

mScan

ZXing 바코드 스캐너 화면으로 직접 시작됩니다 (또는 ZXing이 설치되지 않은 경우 충돌). 바코드가 인식되면

Activity

, 여기

contents

변수 결과가 표시 됩니다.ZXing은 충돌을 피하고 작업을 단순화하기 위해 애플리케이션에 통합하여 ZXing을 더 부드럽게 설치하기 위해 애플리케이션을 통합 할 수

있는 유틸리티 클래스

제공했습니다 .마지막으로 별도의 ZXing 응용 프로그램을 설치하지 않고도 바코드 스캐닝을 응용 프로그램에 직접 통합하려면 오픈 소스 프로젝트이므로 그렇게 할 수 있습니다! :)


편집 :

누군가이 가이드를이 답변으로 편집했습니다 (약간 이상하게 들리지만 정확성에 대해서는 보증 할 수 없으며 2015 년에 Eclipse를 사용하는 이유를 모르겠습니다).

일식에서 zxing 3.2.1을 설정하는 단계별

  1. " https://github.com/zxing/zxing " 에서 zxing-master.zip을 다운로드 하십시오 .
  2. zxing-master.zip의 압축을 풉니 다. 이클립스를 사용하여 zxing-master에서 "android"프로젝트를 가져옵니다.
  3. " http://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/ " 에서 core-3.2.1.jar를 다운로드하십시오.
  4. "android"프로젝트에서 "libs"폴더를 만들고 cor-3.2.1.jar을 libs 폴더에 붙여 넣습니다.
  5. 프로젝트를 클릭하십시오 : "properties"-> "Java Compiler"를 선택하여 레벨을 1.7로 변경하십시오. 그런 다음 1.7을 사용하려면 Android 4.4로 컴파일해야하므로 "Android"를 클릭하고 "프로젝트 빌드 대상"을 android 4.4.2 이상으로 변경하십시오.
  6. "CameraConfigurationUtils.java"가 "zxing-master / android / app / src / main / java / com / google / zxing / client / android / camera /"에없는 경우 "zxing-master / android-core / src / main / java / com / google / zxing / client / android / camera /"에서 복사하여 프로젝트에 붙여 넣을 수 있습니다.
  7. 프로젝트를 정리하고 빌드하십시오. 프로젝트에 "스위치-사례"에 대한 오류가 표시되면 "if-else"로 변경해야합니다.
  8. 완료되었습니다. 프로젝트를 정리하고 빌드하십시오. "속성"> "Android"> "라이브러리"를 클릭하여 프로젝트에 사용할 수 있습니다.

intent.putExtra의 이름에 패키지 이름을 포함해야한다고 설명하는 일부 웹 사이트 (지금은 다시 찾을 수 없음)를 찾을 때까지 코드 구현에 문제가있었습니다.응용 프로그램을 가져 오지만 바코드를 인식하지 못하고 바코드를 변경했을 때 인식하지 못합니다.

intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");

잘 작동했습니다. 다른 초보자 안드로이드 프로그래머를위한 팁.


제공된 IntentInegrator를 사용하는 것이 좋습니다. 바코드 스캐너가없는 경우 사용자에게 바코드 스캐너를 설치하라는 메시지를 표시합니다. 메시지를 사용자 정의 할 수도 있습니다. IntentIntegrator.REQUEST_CODE 상수는 위의 if 블록에서 확인할 onActivityResult의 요청 코드 값을 보유합니다.

IntentIntegrator intentIntegrator = new IntentIntegrator(this); // where this is activity 
intentIntegrator.initiateScan(IntentIntegrator.ALL_CODE_TYPES); // or QR_CODE_TYPES if you need to scan QR

IntentIntegrator.java


Using Zxing this way requires a user to also install the barcode scanner app, which isn't ideal. What you probably want is to bundle Zxing into your app directly.

I highly recommend using this library: https://github.com/dm77/barcodescanner

It takes all the crazy build issues you're going to run into trying to integrate Xzing or Zbar directly. It uses those libraries under the covers, but wraps them in a very simple to use API.


If you want to include into your code and not use the IntentIntegrator that the ZXing library recommend, you can use some of these ports:

I use the first, and it works perfectly! It has a sample project to try it on.


Barcode Detection is now available in Google Play services. Code lab of the setup process, here are the api docs, and a sample project.


You can use this quick start guide http://shyyko.wordpress.com/2013/07/30/zxing-with-android-quick-start/ with simple example project to build android app without IntentIntegrator.

참고URL : https://stackoverflow.com/questions/2050263/using-zxing-to-create-an-android-barcode-scanning-app

반응형