最快的调用Zxing方法
1.关联第三方库
2.调用基础的扫码
3.获取返回值
具体代码如下:
//1.默认选项启动意图 new IntentIntegrator(MainActivity.this).initiateScan(); // `this` is the current Activity //2.获取得到的结果: @Override protected 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,"取消扫码",Toast.LENGTH_LONG).show(); } else { Toast.makeText(this,"扫码结果:" + result.getContents(),Toast.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode,data); } }
MainActivity.java
apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "wei.shm.zxingscancode" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs',include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{ exclude group: '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:使用指定选项创建扫描意图。
以上所述是小编给大家介绍的Android sdutio配置Zxing进行扫码功能的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。