如何获得此条形码扫描仪的“扫描结果类型”

时间:2015-04-23 21:44:37

标签: java android

我在条形码扫描仪应用中显示“扫描结果类型”时出现问题。 textview类型显示空白区域。这是扫描后的样子:

type:

contents:
9715090000007

如果出现错误,请帮助我。这是我的代码:

MainActivity

package dz.androider.qrcodezbar;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.hardware.Camera;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;

import net.sourceforge.zbar.Config;
import net.sourceforge.zbar.ImageScanner;
import net.sourceforge.zbar.Symbol;

public class MainActivity extends Activity {

    private static final int ZBAR_SCANNER_REQUEST = 0;
    private static final int ZBAR_QR_SCANNER_REQUEST = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    
    }

    public void launchScanner(View v) {
        if (isCameraAvailable()) {                
            Intent intent = new Intent(MainActivity.this,
                                       ZBarScannerActivity.class);

            startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
            /*this.setCrop(100,230,600,10);*/
        } else {
            Toast.makeText(this, "Rear Facing Camera Unavailable",
                           Toast.LENGTH_SHORT).show();
        }
    }

    public void launchQRScanner(View v)  {
        if (isCameraAvailable()) {
            Intent intent = new Intent(this, ZBarScannerActivity.class);
            intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
            startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
        } else {
            Toast.makeText(this, "Rear Facing Camera Unavailable",
                            Toast.LENGTH_SHORT).show();
        }
    }

    public boolean isCameraAvailable() {
        PackageManager pm = getPackageManager();
        return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
    }


    public void onActivityResult(int requestCode, int resultCode,
                                                       Intent data) {
        String contents = null;

        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                contents = data.getStringExtra(ZBarConstants.SCAN_RESULT);
                int format = data.getIntExtra(ZBarConstants.SCAN_RESULT_TYPE,0);

                Intent intent = new Intent(getBaseContext(), ScanResults.class);
                intent.putExtra("SCAN_RESULT",contents);
                intent.putExtra("SCAN_RESULT_TYPE",format);

                startActivity(intent);

                // Handle successful scan
            } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
            }
        }
    }
}

ScanResults

package dz.androider.qrcodezbar;

import com.dm.zbar.android.scanner.ZBarConstants;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

  public class ScanResults extends Activity{
    @Override
  protected void onCreate(Bundle savedInstanceState) {
       // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scanresults);

     TextView tv = (TextView) findViewById(R.id.textView4);
    tv.setText(getIntent().getStringExtra("SCAN_RESULT"));
    TextView tv2 = (TextView) findViewById(R.id.textView2);
    tv2.setText(getIntent().getIntExtra("SCAN_RESULT_TYPE",0));

    }

ZbarConstants

package com.dm.zbar.android.scanner;

public interface ZBarConstants {
    public static final String SCAN_MODES = "SCAN_MODES";
    public static final String SCAN_RESULT = "SCAN_RESULT";
    public static final String SCAN_RESULT_TYPE = "SCAN_RESULT_TYPE";
    public static final String ERROR_INFO = "ERROR_INFO";

    public static final int NONE = 0;
    public static final int PARTIAL = 1;
    public static final int EAN8 = 8;
    public static final int UPCE = 9;
    public static final int ISBN10 = 10;
    public static final int UPCA = 12;
    public static final int EAN13 = 13;
    public static final int ISBN13 = 14;
    public static final int I25 = 25;
    public static final int DATABAR = 34;
    public static final int DATABAR_EXP = 35;
    public static final int CODABAR = 38;
    public static final int CODE39 = 39;
    public static final int PDF417 = 57;
    public static final int QRCODE = 64;
    public static final int CODE93 = 93;
    public static final int CODE128 = 128;
}

0 个答案:

没有答案