Android開發 用zxing intent讀取QRcode二維條碼

巨人的肩膀

zxing
Official ZXing (“Zebra Crossing”) project home

journeyapps/zxing-android-embedded
ZXing Android Embedded
Port of the ZXing Android application as an Android library project, for embedding in an Android application.

build.gradle

dependencies {
    //skip...
    compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
    compile 'com.google.zxing:core:3.2.0'
}
`</pre>

### 程式碼範例

<pre>`    public void testClick( View view ){
        IntentIntegrator it = new IntentIntegrator(this);
        it.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
        it.initiateScan();
    }
`</pre>

### 程式碼範例

<pre>`    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        //super.onActivityResult(requestCode, resultCode, data);
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (scanResult != null) {
            String contents = scanResult.getContents();
            if (contents != null) {
                ((TextView)findViewById(R.id.textView)).setText( contents );
            }
        }
    }