Android sdutio配置Zxing进行扫码功能的实现方法
github开源项目(Zxing)demo
最快的调用Zxing方法
1.关联第三方库
2.调用基础的扫码
3.获取返回值
具体代码如下:
//1.默认选项启动意图 newIntentIntegrator(MainActivity.this).initiateScan();//`this`isthecurrentActivity //2.获取得到的结果: @Override protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){ IntentResultresult=IntentIntegrator.parseActivityResult(requestCode,resultCode,data); if(result!=null){ if(result.getContents()==null){ Toast.makeText(this,"取消扫码",Toast.LENGTH_LONG).show(); }else{ Toast.makeText(this,"扫码结果:"+result.getContents(),Toast.LENGTH_LONG).show(); } }else{ super.onActivityResult(requestCode,resultCode,data); } }
MainActivity.java
applyplugin:'com.android.application' android{ compileSdkVersion25 buildToolsVersion"25.0.2" defaultConfig{ applicationId"wei.shm.zxingscancode" minSdkVersion15 targetSdkVersion25 versionCode1 versionName"1.0" testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner" } buildTypes{ release{ minifyEnabledfalse proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' } } } dependencies{ compilefileTree(dir:'libs',include:['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{ excludegroup:'com.android.support',module:'support-annotations' }) compile'com.android.support:appcompat-v7:25.2.0' compile'com.android.support.constraint:constraint-layout:1.0.1' testCompile'junit:junit:4.12' //新建项目只增加这个 compile'com.journeyapps:zxing-android-embedded:3.5.0' //需要核对的有: //1.备置仓库:repositories里的jcenter() //2.com.android.support:appcompat-v7:版本号必须大于23以上 //3.buildToolsVersion:版本需要大于等于23.0.2,旧版本可能会导致编译错误 //以上条件都满足则只需要添加compile'com.journeyapps:zxing-android-embedded:3.5.0' }
IntentIntegrator相关方法注解翻译
setCaptureActivity:设置活动类使用。它可以是任何活动,但应处理的意图额外使用这里。
setPrompt:设置一个提示显示在捕捉屏幕上,而不是使用默认。
setOrientationLocked:默认情况下,方向锁定。设置为false不锁定。
setCameraId:使用指定的相机ID。
setBeepEnabled:设置为false禁用扫描的哔哔声。
setBarcodeImageEnabled:设置为true,以便在结果意图中保存条形码图像并发送其路径。
setDesiredBarcodeFormats:设置所需的条码格式扫描。
initiateScan:启动扫描所有已知的条形码类型与默认相机。
setTimeout:启动扫描所有已知的条形码类型与默认相机。并启动计时器超时完成
createScanIntent:使用指定选项创建扫描意图。
以上所述是小编给大家介绍的Androidsdutio配置Zxing进行扫码功能的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!