主要功能扫码二维码,使用ZXing实现 ;
感觉Zxing这个库扫码的速度和识别率一般,腾讯和阿里这些大佬们的扫码功能也没有开源;
额,不说废话了 先看图吧;
好了,看一下我们这个库的扫码怎么使用;
1、初始化;推荐放在Applocation中;
FastZxingApp.init(MainActivity.this.getApplication());
2、Android6.0动态权限:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {//扫描需要用到相机权限、读取相册需要用到读取文件权限;ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA , Manifest.permission.READ_EXTERNAL_STORAGE}, 1);}
3、开始扫码和回调:
public void scan(View view) {startActivityForResult(new Intent(this, ScanActivity.class) , REQUESTCODE);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == REQUESTCODE && resultCode == RESULT_OK){et.setText("扫描结果:"+data.getExtras().getString(ScanUtils.RESULT_STRING));}}
好了,完成了;
源码在这里:FastZxing
想要自定义UI或什么的,直接下载项目,扫码的代码全在一个类库中,随便改;