我使用 Zxing 库读取 QR/BarCode,目前我的项目正在从 Sdcard 读取 Qr/Barcode 并对其进行解码
我想使用我的设备相机扫描代码然后解码,我如何更改我的代码以便它在这里工作。
这是我的代码
public static class Global
{
public static String text=null;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bMap = BitmapFactory.decodeFile("/sdcard/2.gif");
TextView textv = (TextView) findViewById(R.id.mytext);
View webbutton=findViewById(R.id.webbutton);
LuminanceSource source = new RGBLuminanceSource(bMap);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new MultiFormatReader();
try {
Result result = reader.decode(bitmap);
Global.text = result.getText();
byte[] rawBytes = result.getRawBytes();
BarcodeFormat format = result.getBarcodeFormat();
ResultPoint[] points = result.getResultPoints();
textv.setText(Global.text);
webbutton.setOnClickListener(this);
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ChecksumException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
Uri uri = Uri.parse(Global.text);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}