Giter Site home page Giter Site logo

qrcode-android's Introduction

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

生成二维码

qrcode-android's People

Contributors

xudaojie avatar honghe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.