我是android新手。我試圖開發一款條形碼掃描器,其工作原理如下: 通過相機拍攝(條形碼)圖像並掃描此條形碼圖像。 我的問題是我如何做到這一點? 在此先感謝條碼圖像掃描儀
這裏是我的代碼:
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.");
}
}
}
}
我感到困惑如何獲取攝像機圖像,並把它傳遞給掃描儀掃描... – zain
IntentIntegrator積分=新IntentIntegrator (yourActivity); integrator.initiateScan(); 我已經打電話給onCreate,當我嘗試用我的avtivity類名稱替換yourActivity時,出現錯誤。 – zain
@Zain嘗試他們提供的示例應用程序。這將爲您提供指導。 –