扫描二维码
来源:互联网 发布:jq 加载js 跨域 编辑:程序博客网 时间:2024/05/02 08:47
zxing库下载地址:http://download.csdn.net/detail/xiaruoli89/9536545
需要依赖zxing这个module
布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="zxing.my.com.zxingdemo.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始扫描" android:id="@+id/button" android:onClick="scan" android:layout_gravity="center_horizontal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:text="result:"/> <TextView android:id="@+id/tv_result" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" /></LinearLayout>
代码:
private TextView tv_result;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv_result= (TextView) findViewById(R.id.tv_result);}public void scan(View v){ startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class),0);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK){ Bundle bundle=data.getExtras(); tv_result.setText(bundle.getString("result")); }}
在百度上找个二维码生成器,随便写一段文字,生成二维码,然后扫描后的信息就会出现在tv_result里了
0 0
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 扫描二维码
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 扫描二维码
- 二维码扫描
- 二维码扫描
- 扫描二维码
- java多线程---顺序打印ABC的三种实现---join方法
- 创建uv动画
- Java网络编程——基于TCP的Socket编程
- A+B Problem (Case Count)
- 解决卸载wifi共享软件后无法连网的问题
- 扫描二维码
- 定义派生类
- POJ 1515 双联通分量
- 2016年3月编程语言排行榜,与十年前相比前十名并无变化
- Eclipse如何安装WindowBuilder插件及如何使用WB
- Js apply方法详解
- Android Invalid maximum heap size: -Xmx 解决方法
- MySQL中char与varchar数据类型选择原则
- java常用排序算法