本文介绍了Zxing新动态扫描结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经加入Zxing 3.0.1作为库项目中,我有2个布局:第一次我有按钮,叫 CaptureActivity Zxing库,然后在 CaptureActivit Ÿ德codeA酒吧codeI需要把这个code上的第二布局成的的TextView 的。我怎样才能做到这一点?如果有人知道,请写一步一步的手动,因为在和Android初学者,不知道该怎么code。

我必须把东西code,这部分的 CaptureActivity

 公共无效的onActivityResult(INT申请code,INT结果code,意图意图){
如果(结果code == RESULT_OK){
  如果(要求code == HISTORY_REQUEST_ code){    INT itemNumber = intent.getIntExtra(Intents.History.ITEM_NUMBER,-1);
    如果(itemNumber> = 0){
      HistoryItem historyItem = historyManager.buildHistoryItem(itemNumber);
      德codeOrStoreSavedBitmap(NULL,historyItem.getResult());
    }
  }
}
}


解决方案

YOUT必须与启动CaptureActivity startActivityForResult

  startActivityForResult(新意图(这一点,CaptureActivity.class),CaptureActivity.REQUEST_ code);

在Zxing与解码完成(在我的情况下,它返回它的结果的 handleResult(结果rawResult) callback-你应该叫的setResult(RESULT_OK,数据)里面CaptureActivity哪里数据 - 是您去$ C $随机附送的字符串和呼叫完成()

  @覆盖
公共无效handleResult(结果rawResult){
    捆绑数据=新包();
    args.putString(RESULT_KEY,rawResult.getText());
    的setResult(RESULT_OK,数据);
    完();
}

在始于CaptureActivity你必须重写的onActivityResult(INT申请code,INT结果code,意图数据)的回调和处理得到的结果活动 - 你的情况 - 更新中TextView的:

 公共无效的onActivityResult(INT申请code,INT结果code,意图意图){
   如果(要求code == CaptureActivity.REQUEST_ code和;&安培;结果code == RESULT_OK){
       youtTextView.post(新的Runnable(){
           @覆盖
           公共无效的run(){
               yourTextView.setText(intent.getStringExtra(RESULT_KEY));
           }
       };
   }
}

I have added Zxing 3.0.1 as a library to my project I have 2 layouts: on first i have button which call CaptureActivity of Zxing library, and when CaptureActivity decode a barcode i need to put this code on a second layout into textView. How can i do this? If someone know, please write step-by-step manual, because in and Android beginner, and dont know what to code .

I must put something this part of code CaptureActivity?

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (resultCode == RESULT_OK) {
  if (requestCode == HISTORY_REQUEST_CODE) {

    int itemNumber = intent.getIntExtra(Intents.History.ITEM_NUMBER, -1);
    if (itemNumber >= 0) {
      HistoryItem historyItem = historyManager.buildHistoryItem(itemNumber);
      decodeOrStoreSavedBitmap(null, historyItem.getResult());
    }
  }
}
}
解决方案

Yout have to start CaptureActivity with startActivityForResult:

startActivityForResult(new Intent(this, CaptureActivity.class), CaptureActivity.REQUEST_CODE);

When Zxing done with decoding (in my case it return it's result in handleResult(Result rawResult) callback- you should call setResult(RESULT_OK, data) inside CaptureActivity where data - is your decoded bundled string and call finish():

@Override
public void handleResult(Result rawResult) {
    Bundle data = new Bundle();
    args.putString(RESULT_KEY, rawResult.getText());
    setResult(RESULT_OK, data);
    finish();
}

In Activity which started CaptureActivity you have to override onActivityResult(int requestCode, int resultCode, Intent data) callback and handle getting result - in your case - update a TextView:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == CaptureActivity.REQUEST_CODE && resultCode == RESULT_OK) {
       youtTextView.post(new Runnable() {
           @Override
           public void run() {
               yourTextView.setText(intent.getStringExtra(RESULT_KEY));
           }
       };
   }
}

这篇关于Zxing新动态扫描结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 15:54