Android - 二维码扫一扫

1、教学视频:慕课网 http://www.imooc.com/note/648?sort=last

2、第三方包ZXing实现二维码扫描解析与生成功能;

3、Android Studio 项目目录:1、app  2、libzxing,app引用libzxing Module;

4、源代码:

  解析二维码: startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class), 0); //0:requestCode

         protected void onActivityResult(int requestCode, int resultCode, Intent data) {...}

  生成二维码: EncodingUtils.createQRCode("codeText", 500, 500, logoBitmap) ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.yizhui.qrcode.MainActivity">
 
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/scan_qrcode"
        android:onClick="scan"/>
    <TextView
        android:id="@+id/qrCodeResult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        />
    <EditText
        android:id="@+id/qrCodeText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/make_qrcode"
        android:onClick="make"/>
    <CheckBox
        android:id="@+id/chk_useLogo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/use_logo"/>
    <ImageView
        android:id="@+id/qrCodeImageView"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

  

posted @   chenyizh  阅读(599)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示