如何使用zxing庫獲取自定義掃描儀的掃描條形碼結果?活動結果不起作用。掃描部分工作正常,並得到結果。但是我沒有收到活動結果中的任何數據。如何獲得條碼掃描器android的活動結果?
public class ScannerActivity extends Activity implements ZXingScannerView.ResultHandler{
ResultHandler resultHandler;
Parameters parameters;
private CaptureManager capture;
private CompoundBarcodeView barcodeScannerView;
private Button switchFlashlightButton;
private ZXingScannerView mScannerView;
BarcodeView test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_scanner);
Bundle extras = this.getIntent().getExtras();
resultHandler = (ResultHandler) extras.getSerializable("RESULT_HANDLER");
parameters = (Parameters) extras.getSerializable("PARAMETERS");
barcodeScannerView = (CompoundBarcodeView)findViewById(R.id.zxing_barcode_scanner);
this.getIntent().putExtra("Result_handle",resultHandler);
capture = new CaptureManager(this, barcodeScannerView);
capture.initializeFromIntent(getIntent(), savedInstanceState);
capture.decode();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Log.d("onActivityResult", "onActivityResult: .");
if (resultCode == Activity.RESULT_OK) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
String re = scanResult.getContents();
String message = re;
Log.d("onActivityResult", "onActivityResult: ."+ re);
Result handlerResult = new Result(Result.STATUS_SUCCESS, "qrcode", message);
resultHandler.onHandleResult(handlerResult);
this.finish();
}
// else continue with any other code you need in the method
}
@Override
protected void onResume() {
Log.d("onResume", "onResume: .");
super.onResume();
capture.onResume();
}
@Override
protected void onPause() {
Log.d("onPause", "onPause: .");
super.onPause();
capture.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
capture.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
Log.d("onSaveInstanceState", "onSaveInstanceState: .");
super.onSaveInstanceState(outState);
capture.onSaveInstanceState(outState);
}
}
你怎麼發的結果?請分享您的代碼 – 0X0nosugar
這就是結果。但它來自CaptureManager.java類,它是一個庫 protected void returnResult(BarcodeResult rawResult){ Intent intent = resultIntent(rawResult,getBarcodeImagePath(rawResult)); activity.setResult(Activity.RESULT_OK,intent); finish(); } https://github.com/journeyapps/zxing-android-embedded/blob/master/zxing-android-embedded/src/com/journeyapps/barcodescanner/CaptureManager.java – jgm
我想知道是否有可能任何衝突,因爲你似乎在同一活動中要求和接收結果*。通常ActivityA會「startActivityForResult(ActivityA.this,ActivityB.class);」然後AcitivtyB會(通過「getIntent()」)確定它應該做什麼,最後調用「setResult()」和「finish()」。然後最後調用ActivityA的「onActivityResult()」。 – 0X0nosugar