205506625/BarcodeScaner

ZXing Barcode Scanner 仿微信二维码扫描

★ 0Forks 0JavaGitHub ↗Compare

README

BarcodeScaner

仿微信二维码扫描,基于journeyapps/ zxing-android-embedded开发

Screenshot

Usage Xml

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

    <com.journeyapps.barcodescanner.CompoundBarcodeView
        android:id="@+id/zxing_barcode_scanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

Usage Code

Put the following code in your Activity.onCreate() method

private void initCaptureManager(Bundle savedInstanceState) {
        barcodeScannerView = (CompoundBarcodeView) findViewById(R.id.zxing_barcode_scanner);
        capture = new CaptureManager(this, barcodeScannerView);
        capture.initializeFromIntent(getIntent(), savedInstanceState);
        capture.setOnBarcodeCallBack(this);
        capture.decode();
}

You can receive and handle your result after scan through implement the interface CaptureManager.OnBarcodeCallBack

 @Override
    public void onBarcodeResult(String content) {
        Intent data = new Intent();
        data.putExtra(EXTRA_SCAN_RESULT, content);
        setResult(RESULT_OK, data);
        finish();
    }

And Handling the Scanner's lifecycle in your Activity

    @Override
    protected void onResume() {
        super.onResume();
        capture.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        capture.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        capture.onDestroy();
    }

You could also handling the OnKeyDownEvent by call the CompoundBarcodeView.onKeyDown(keyCode, event).

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return barcodeScannerView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
    }

Adding aar dependency

  1. download the sample

  2. Android Studio : File - New - Import Module, and choose source directory

  3. Add the following to your build.gradle file:

    dependencies {
         compile project(':zxing-barcoder-embed')
    }
    

Notice: For more information you can visit the repository zxing-android-embedded. And Thanks for the help journeyapps again.

Developed by

Name: ZTerry Liu
E-mail: [email protected]
Subject: BarcodeScaner

Contributors

lztataliuzhanta

Issues