标签:init cap capture start demo over compile length extra
1.在module的build.gradle中执行compile操作
compile ‘cn.yipianfengye.android:zxing-library:2.2‘
2.在demo Application中执行初始化操作
@Override public void onCreate() { super.onCreate(); ZXingLibrary.initDisplayOpinion(this); }
3.在代码中执行打开扫描二维码界面操作
Intent intent = new Intent(MainActivity.this, CaptureActivity.class); startActivityForResult(intent, REQUEST_CODE);
//这里的REQUEST_CODE是我们定义的int型常量
4.在Activity的onActivityResult方法中接收扫描结果
/** * 处理二维码扫描结果 */ if (requestCode == REQUEST_CODE) { //处理扫描结果(在界面上显示) if (null != data) { Bundle bundle = data.getExtras(); if (bundle == null) { return; } if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) { String result = bundle.getString(CodeUtils.RESULT_STRING); Toast.makeText(this, "解析结果:" + result, Toast.LENGTH_LONG).show(); } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) { Toast.makeText(MainActivity.this, "解析二维码失败", Toast.LENGTH_LONG).show(); } } }
标签:init cap capture start demo over compile length extra
原文地址:https://www.cnblogs.com/monkey0928/p/9751158.html