这个库对 进行了封装,使用方便也可扩展
集成:
compile 'com.google.zxing:core:3.3.0' compile 'com.journeyapps:zxing-android-embedded:3.5.0'
调用:
new IntentIntegrator(this).initiateScan();//或者IntentIntegrator integrator = new IntentIntegrator(ScanActivity.this);integrator.setPrompt("扫描");integrator.setCameraId(0); //前置|后置摄像头integrator.setBeepEnabled(true); //扫描成功提示音integrator.setOrientationLocked(false);//方向锁定integrator.initiateScan();// 回调:@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if(result != null) { if(result.getContents() == null) { Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode, resultCode, data); }}
现在是个横向的扫描,体验不是很好,如需竖屏在清单中添加: