我是安卓新手。我正在尝试开发一个条形码扫描仪,其工作原理如下:通过相机拍摄(条形码)图像并扫描此条形码图像。我的问题是我该怎么做?提前致谢
这是我的代码:
TextView result_text;
Button scan_btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
result_text = (TextView)findViewById(R.id.Result_tv);
scan_btn = (Button)findViewById(R.id.Barcode_Scan_Button);
scan_btn.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent scanIntent= new Intent("com.google.zxing.client.android.SCAN");
scanIntent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(scanIntent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
result_text.setText(intent.getStringExtra("SCAN_RESULT"));
} else if (resultCode == RESULT_CANCELED) {
result_text.setText("Scan cancelled.");
}
}
}
}