Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
/ QRCode-Android Public archive

二维码、条形码通用扫描(已停止维护)

Notifications You must be signed in to change notification settings

XuDaojie/QRCode-Android

Repository files navigation

QRCode

JitPack API
本项目依赖于ZXing 3.2.1
对6.0以上和第三方ROM自带的权限增加了权限判断

Scan

Use

Add permission

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Register activity

<activity android:name="io.github.xudaojie.qrcodelib.CaptureActivity"/>

Code

CaptureActivity 对二维码扫描信息默认是将扫描结果传回上一个界面,如果你要在CaptureActivity中直接处理,可通过重写handleResult(String resultString)实现

直接使用

Intent i = new Intent(mContent, CaptureActivity.class);
startActivityForResult(i, REQUEST_QR_CODE);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK
            && requestCode == REQUEST_QR_CODE
            && data != null) {
        String result = data.getStringExtra("result");
        Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
    }
}

重写handleResult(String resultString)

public class SimpleCaptureActivity extends CaptureActivity {
     @Override
    protected void handleResult(String resultString) {
        if (resultString.equals("")) {
            Toast.makeText(mActivity, R.string.scan_failed, Toast.LENGTH_SHORT).show();
            restartPreview();
        } else {
            // TODO: 16/9/17 ... 
//        restartPreview();
        }
    }
}

Tips
如果你的操作不会触发SimpleCaptureActivityonPauseonResume生命周期,则需要在完成操作后,调用restartPreview()以重新启动扫描

Including in your project

Add repository

想引入你的项目,需要修改你的build.gradle

repositories {
    maven { url "http://repo1.maven.org/maven2" }
    maven { url 'https://jitpack.io' }
}

Add dependency

compile 'com.github.XuDaojie:QRCode-Android:v0.4.2'

吃水不忘挖井人

ZXing
zxing扫描二维码和识别图片二维码及其优化策略

TODO

生成二维码

About

二维码、条形码通用扫描(已停止维护)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages