扫描二维码
来源:互联网 发布:中文calypso软件安装 编辑:程序博客网 时间:2024/06/05 10:59
先在androidstudio上导入libzing的Module,然后再app上把那个libzing添加上去,这样我们的app就关联了那个libzing库了
然后我们就只在app这个工程下写代码就行了。activity_main.xml布局如下
<?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" tools:context="com.example.qrcode.MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="scan" android:text="扫描二维码" /> <TextView android:id="@+id/tv_ruselt" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="26sp" /> <EditText android:id="@+id/et_text" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="make" android:text="生成二维码" /> <CheckBox android:id="@+id/is_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="check" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@mipmap/ic_launcher" /></LinearLayout>
Mainactivity.java
public class MainActivity extends AppCompatActivity { private TextView mTv_Ruslet; private EditText mInput; private ImageView mImg; private CheckBox isLogo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTv_Ruslet = (TextView) findViewById(R.id.tv_ruselt); mInput = (EditText) findViewById(R.id.et_text); mImg = (ImageView) findViewById(R.id.img); isLogo = (CheckBox) findViewById(R.id.is_logo); } /** * 生成二维码 */ public void make(View view) { String input = mInput.getText().toString().trim(); //生成二维码,然后为二维码增加logo Bitmap bitmap = EncodingUtils.createQRCode(input, 500, 500, isLogo.isChecked() ? BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher) : null ); mImg.setImageBitmap(bitmap); } /** * 扫描二维码 */ public void scan(View view) { startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class), 0); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); String result = bundle.getString("result"); mTv_Ruslet.setText(result); mInput.setText(result); } else if (resultCode == RESULT_CANCELED) { mTv_Ruslet.setText("扫描出错"); } }}注意一下,版本必须在16或16以上
运行结果:扫描跟生成二维码都是ok的
阅读全文
0 0
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 扫描二维码
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 二维码扫描
- 扫描二维码
- 二维码扫描
- 二维码扫描
- 扫描二维码
- Angular 4入门教程系列:7:Tour Of Heroes之路由
- 二维码扫描
- fresco
- linux基础(五)用户管理、umask、忘记root密码如何解决
- 百度首页
- 扫描二维码
- 爱奇艺首页
- 自定义view
- NYOJ1170 最大的数
- 自定义画圆
- MySQL 学习教程(六)【整理】-主键冲突/ 蠕虫复制/ 更新/ 删除
- MVP+Rectrofit+RXJAVA+Fresco
- 【AtCoder Regular Contest 066 F】【JZOJ 5451】Contest with Drinks Hard
- 【第11章】【预置的ChannelHandler和解码器】