扫描生成二维码 添加依赖zxing
来源:互联网 发布:知乎大神侵权 编辑:程序博客网 时间:2024/04/28 05:31
添加依赖
//把zxing包添加到新建的工程 <!-- 相机 --> <uses-permission android:name="android.permission.CAMERA" /> <!-- 振动 --> <uses-permission android:name="android.permission.VIBRATE" /> <activity android:name="com.xys.libzxing.zxing.activity.CaptureActivity"> </activity>
布局文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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"> <Button android:id="@+id/btnSan" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="扫描二维码" /> <TextView android:id="@+id/tv_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btnSan" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" /> <EditText android:id="@+id/et_input" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv_content" android:layout_marginTop="10dp" android:hint="请输入要生成的二维码文字" /> <Button android:id="@+id/btn_generate" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/et_input" android:layout_marginTop="10dp" android:text="生成二维码" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btn_generate" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" /></RelativeLayout>
MainActivity
public class MainActivity extends AppCompatActivity { private TextView tv_content; private EditText et_input; private ImageView img; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv_content = (TextView) findViewById(R.id.tv_content); et_input = (EditText) findViewById(R.id.et_input); img = (ImageView) findViewById(R.id.img); findViewById(R.id.btnSan).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class), 0); } }); findViewById(R.id.btn_generate).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String str = et_input.getText().toString(); if (str.equals("")) { Toast.makeText(MainActivity.this, "不能为空", Toast.LENGTH_SHORT).show(); } else { // 位图 try { //参数:1.文本 2 3.二维码的宽高 4.二维码中间的那个logo Bitmap bitmap = EncodingUtils.createQRCode(str, 500, 500, null); // 设置图片 img.setImageBitmap(bitmap); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { String result = data.getExtras().getString("result"); Log.d("Main", result); tv_content.setText(result); } }}
阅读全文
0 0
- 扫描生成二维码 添加依赖zxing
- Zxing二维码扫描生成
- Zxing二维码、条形码扫描/生成
- Android生成二维码和扫描二维码zxing
- 使用ZXing扫描二维码和生成二维码
- 二维码的生成,扫描(ZXing开源的依赖库)
- Android二维码的扫描和生成(ZXing)
- zxing框架扫描和生成二维码
- Zxing实现二维码生成,扫描代码段
- 使用ZXing扫描和生成二维码
- 二维码生成、扫描、图片识别(Zxing)
- Android zxing,轻松实现二维码扫描、生成
- ZXing二维码、条形码生成和扫描
- 基于Zxing的二维码生成和二维码扫描
- Android-扫描二维码、生成二维码(Zxing库)
- 基于Zxing的二维码生成和二维码扫描
- Android基于Zxing实现二维码,条形码扫描和生成二维码
- 基于Zxing的二维码生成和二维码扫描
- Apache Zeppelin 中 Elasticsearch 解释器
- 使用hiredis LPUSH 一个带空格的Json字符串到redis 会被分隔成多段的问题
- 进程环境
- 28个JavaScript常用代码集合,前端老司机问你怕不怕!
- 纯手工系列--零配置实现Spring MVC+Spring Data JPA
- 扫描生成二维码 添加依赖zxing
- 数据结构——树——二叉搜索树
- HTTP协议(下):HTTP协议实现通信
- swiper 插件 一些基本配置
- C#——冒泡排序
- JVM调优总结(九)-新一代的垃圾回收算法
- Git中从远程的分支获取最新的版本到本地——两种命令
- CG中的深度学习 |Siggraph 2017 相关论文总结
- java 定义新枚举enum