Giter Club home page Giter Club logo

yzxing's Introduction

YZxing

一款仿微信扫一扫界面,基于zxing实现的扫码库。

实现效果

image image

使用方式

首先通过在build.gradle文件中添加如下编译语句将YZxing-lib库添加到项目中。
compile 'com.yangy:YZxing-lib:1.1'
(或者在直接把本仓库里面的YZxing库下载下来,添加到项目中。)
然后在点击跳转到扫码界面的点击事件中,调用如下方法:
Intent intent = new Intent(this, ScannerActivity.class);
//这里可以用intent传递一些参数,比如扫码聚焦框尺寸大小,支持的扫码类型。
// //设置扫码框的宽
// intent.putExtra(Constant.EXTRA_SCANNER_FRAME_WIDTH, 400);
// //设置扫码框的高
// intent.putExtra(Constant.EXTRA_SCANNER_FRAME_HEIGHT, 400);
// //设置扫码框距顶部的位置
// intent.putExtra(Constant.EXTRA_SCANNER_FRAME_TOP_PADDING, 100);
// Bundle bundle = new Bundle();
// //设置支持的扫码类型
// bundle.putSerializable(Constant.EXTRA_SCAN_CODE_TYPE, mHashMap);
// intent.putExtras(bundle);
startActivityForResult(intent, RESULT_REQUEST_CODE);

这里可以使用intent传递一些配置参数。支持有设置扫码框的大小,及位置;设置支持的扫码类型。目前支持的自定义配置不多,后续有机会再扩充。 跳转的时候要有startActivityForResult来跳转,这样在扫码成功之后,返回的结果可以在onActivityResult方法中处理代码如下:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {

        switch (requestCode) {  
        
            case RESULT_REQUEST_CODE:  
            
                if (data == null) return;  
                
                String type = data.getStringExtra(Constant.EXTRA_RESULT_CODE_TYPE);  
                
                String content = data.getStringExtra(Constant.EXTRA_RESULT_CONTENT);  
                
                Toast.makeText(MainActivity.this,"codeType:" + type  
                
                        + "-----content:" + content,Toast.LENGTH_SHORT).show();  
                        
                break;  
                
            default:  
            
                break;  
                

        }  
        
    }  
    
    super.onActivityResult(requestCode, resultCode, data);  
    
}  

觉得还不错的就动动手指给个star吧(^__^)

 

yzxing's People

Contributors

mryangy 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.