如何在Android中显示扫描结果?

时间:2014-04-24 11:33:10

标签: android zxing barcode-scanner

我想显示ZXING的扫描结果。我将ZXING集成到我的Android应用程序中,扫描工作正常。现在我想使用扫描结果更新主要活动中的TextView。

4 个答案:

答案 0 :(得分:1)

调用

Intent intent = new Intent("<span class="skimlinks- unlinked">com.google.zxing.client.android.SCAN</span>");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);

获得结果:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
         String contents = intent.getStringExtra("SCAN_RESULT");
         String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
         // Handle successful scan
      } else if (resultCode == RESULT_CANCELED) {
         // Handle cancel
      }
   }
}

关注this教程了解更多信息

答案 1 :(得分:1)

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
String contents = null;
String format=null;
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
  if (resultCode == RESULT_OK) {
     contents = data.getStringExtra("SCAN_RESULT");
     format = data.getStringExtra("SCAN_RESULT_FORMAT");
     //moved here
     TextView tv1 = (TextView) findViewById(R.id.scanFormat);
     tv1.setText(format);


     TextView tv = (TextView) findViewById(R.id.scanResult);
     tv.setText(contents);
     // Handle successful scan
  } else if (resultCode == RESULT_CANCELED) {
     // Handle cancel
  }
}

并在您的活动中添加此内容

  @Override
  public void onConfigurationChanged(Configuration newConfig){        
  super.onConfigurationChanged(newConfig);
  }

并在巡回活动的清单文件中:

    android:configChanges="orientation|keyboardHidden"

答案 2 :(得分:0)

我能够在帮助下成功开发条码扫描应用程序 Create a Barcode Scanner usingg Zxing library

它可能也有帮助..或任何想要开发条码扫描应用程序的人!

答案 3 :(得分:0)

historyManager = new HistoryManager(this);
        historyManager.trimHistory();

        Intent intent = getIntent();

        int itemNumber = intent.getIntExtra(Intents.History.ITEM_NUMBER, -1);
        //Log.d(TAG ,"ITEM NUMBER =>" +itemNumber);
        if (itemNumber >= 0) {
            historyItem = historyManager.buildHistoryItem(itemNumber);

            decodeOrStoreSavedBitmap(null, historyItem.getResult());
            Log.d(TAG ,"ITEM NUMBER =>" +historyItem.getResult());
        }