二维码
程序员文章站
2022-07-14 18:18:22
...
在生活中我们经常用到二维码,下面我们自己集成一个二维码。
首先在主build.gradle里面鞋
allprojects {
repositories {
google()
jcenter()
maven { url ‘https://jitpack.io’ }
}
}
然后自己项目的build.gradle 里面导入依赖:
implementation ‘com.github.jwkj:LibZXing:v1.0.4’
清单文件权限配置
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
在mainactivity里
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(this, "走了:", Toast.LENGTH_SHORT).show();
//注册onActivityResult
QRCodeManager.getInstance().with(this).onActivityResult(requestCode, resultCode, data);
}
配置完成开始写代码:
//这是扫描:
case R.id.bt3:
QRCodeManager.getInstance()
.with(getActivity())
.setReqeustType(0)
.scanningQRCode(new OnQRCodeScanCallback() {
@Override
public void onCompleted(String s) {
Toast.makeText(getActivity(), "结果:" + s, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Throwable throwable) {
Toast.makeText(getActivity(), "错误:" + throwable.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(getActivity(), "扫描任务取消了", Toast.LENGTH_SHORT).show();
}
});
break;
case R.id.bt4:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Bitmap logo_qRcode = QRCodeManager.getInstance().createQRCode("ZXingCode", 400, 400, bitmap);
ion_qq.setImageBitmap(logo_qRcode);
break;
case R.id.bt5:
Bitmap logo_qRcode1 = QRCodeManager.getInstance().createQRCode("ZXingCode", 400, 400);
ion_qq.setImageBitmap(logo_qRcode1);
break;
上一篇: 项目记录:GPU硬解码渲染
下一篇: 视频GPU硬解码方案对比