在工程build添加依赖
compile 'cn.yipianfengye.android:zxing-library:2.2'
在
AppCompatActivity中
@Override public void onCreate() { super.onCreate(); ZXingLibrary.initDisplayOpinion(this); } }@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); 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(); Intent it=new Intent(MainActivity.this,TwoActivity.class); String string="嘻嘻"; it.putExtra("haha",string); startActivity(it); } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) { Toast.makeText(MainActivity.this, "解析二维码失败", Toast.LENGTH_LONG).show(); } } } }