利用 ZXing Android Embedded 实现二维码处理

本文介绍了如何使用 ZXing Android Embedded 开源库在 Android 上实现二维码的扫描和生成。首先,通过在 build.gradle 文件中添加依赖来引入库。接着展示了如何创建布局并启动扫描,以及自定义扫描界面为竖屏。然后,通过 onActivityResult() 处理扫码结果。最后,讲解了如何生成二维码,只需输入文字,点击按钮即可完成。源码可在 GitHub 查看。
摘要由CSDN通过智能技术生成

ZXing Android Embedded 是一个非常好用的开源库,对于 ZXing 在 Android 上的应用方法进行了精简。这里简单地用一个小 demo 来练习对此库的使用。

引用开源库

Android Studio 引用方法相当简单,直接在 build.gradle 文件里加入如下代码:

repositories {
    jcenter()
}

dependencies {
    compile 'com.journeyapps:zxing-android-embedded:3.4.0'
    compile 'com.android.support:appcompat-v7:23.1.0'   // Version 23+ is required
}

android {
    buildToolsVersion '23.0.2' // Older versions may give compile errors
}

扫描二维码

新建一个项目,在布局文件里设置简单的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:contex
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值