安卓扫码Zxing旋转90及270度
程序员文章站
2022-07-14 17:34:40
...
网上找了很多Zxing库一般正常手机都可以用,但是公司自己产的三防手机摄像头需要旋转270度,但是画面正常了扫码却不回调了。是因为引用的库被阉割了。
附上库文件路径:安卓实现扫码的Zxing库-CSDN下载 https://download.csdn.net/download/xbj1015892775/10666915
引用到项目中
在自己项目中添加如下即可。
//扫码
//扫码按钮下添加点击事件
findViewById(R.id.ll_scan).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getRuntimeRight();
}
});
/**
* 获得运行时权限
*/
private void getRuntimeRight() {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, 1);
} else {
jumpScanPage();
}
}
/**
* 跳转到扫码页
*/
private void jumpScanPage() {
startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class), CaptureActivity.REQ_CODE);
}
//这里是扫码获取到的回调
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CaptureActivity.REQ_CODE:
switch (resultCode) {
case RESULT_OK:
tvResult.setText(data.getStringExtra(CaptureActivity.EXTRA_SCAN_RESULT)); //or do sth
break;
case RESULT_CANCELED:
if (data != null) {
// for some reason camera is not working correctly
tvResult.setText(data.getStringExtra(CaptureActivity.EXTRA_SCAN_RESULT));
}
break;
}
break;
}
//data.getStringExtra(CaptureActivity.EXTRA_SCAN_RESULT)这个就是获取到的值
}
附上库文件路径:安卓实现扫码的Zxing库-CSDN下载 https://download.csdn.net/download/xbj1015892775/10666915
上一篇: 字符设备驱动(一)
推荐阅读