Zxing条形码扫描器在与Android应用程序

时间:2017-02-08 06:55:47

标签: java android zxing

您已将Zxing扫描仪成功集成到我的应用程序中,但我遇到的问题是它不想扫描条形码,但它可以完美地扫描qr代码。当我打开Zxing应用程序时,条形码扫描仪可以工作。当我从我正在构建的应用程序启动它时它才起作用。有没有人以前遇到过这个问题并找到解决方案?

 static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";


        //product barcode mode
        public void scanBar(View v) {
            try {

                Intent intent = new Intent(ACTION_SCAN);
                intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
                startActivityForResult(intent, 0);
            } catch (ActivityNotFoundException anfe) {
                //on catch, show the download dialog
                showDialog(BarcodeScanner.this, "No Scanner Found",  "Download a  scanner code activity?", "Yes", "No").show();
            }
        }

        // start qr stuff  //product qr code mode
        public void scanQR(View v) {
            try {
                //start the scanning activity from the   com.google.zxing.client.android.SCAN intent
                Intent intent = new Intent(ACTION_SCAN);
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                startActivityForResult(intent, 0);
            } catch (ActivityNotFoundException anfe) {
                //on catch, show the download dialog
                showDialog(BarcodeScanner.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();
            }
        }

        //alert dialog for downloadDialog
        private static AlertDialog showDialog(final Activity act,  CharSequence title, CharSequence message, CharSequence buttonYes,  CharSequence buttonNo) {
            AlertDialog.Builder downloadDialog = new  AlertDialog.Builder(act);
            downloadDialog.setTitle(title);
            downloadDialog.setMessage(message);
            downloadDialog.setPositiveButton(buttonYes, new   DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    Uri uri = Uri.parse("market://search?q=pname:" +  "com.google.zxing.client.android");
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    try {
                        act.startActivity(intent);
                    } catch (ActivityNotFoundException anfe) {

                    }
                }
            });
             downloadDialog.setNegativeButton(buttonNo, new    DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            });
            return downloadDialog.show();
           }
            //on ActivityResult method
           public void onActivityResult(int requestCode, int resultCode, Intent intent) {
              if (requestCode == 0) {
                if (resultCode == RESULT_OK) {
                   //get the extras that are returned from the intent
                    String tagNo = intent.getStringExtra("SCAN_RESULT");
                    String format =    intent.getStringExtra("SCAN_RESULT_FORMAT");
                    MySOAPCallActivity cs = new MySOAPCallActivity();

                    //tagNo = editTagNumber.getText().toString();

                    final GlobalClass globalVariable = (GlobalClass)     getApplicationContext();

                    // Get name and email from global/application context
                    String eventName  = globalVariable.getEventName();
                    if(Local.isSet(getApplicationContext(), "EventName"))
                    {
                        eventName = Local.Get(getApplicationContext(), "EventName");

                    }
                    if(eventName.length() > 0) {

                       TagParams params = new TagParams(cs, tagNo, eventName);

                        //Make yes no buttons visible
                        Button buttonYes =     (Button)findViewById(R.id.buttonYes);
                        Button buttonNo = (Button)findViewById(R.id.buttonNo);
                       buttonYes.setVisibility(View.VISIBLE);
                       buttonNo.setVisibility(View.VISIBLE);

                        TextView nameSurname = (TextView)    findViewById(R.id.nameSurname);
                        nameSurname.setText("");
                        TextView idNumber = (TextView) findViewById(R.id.idNumber);
                        idNumber.setText("");
                        TextView ticketClass = (TextView)    findViewById(R.id.ticketClass);
                        ticketClass.setText("");



                        new CallSoapTicketValidForEvent().execute(params);
                    }

                }

                ;
            }
        }

这是gradle

apply plugin: 'com.android.application'

android {
        signingConfigs {
        }
        compileSdkVersion 23
        buildToolsVersion '23.0.1'
        defaultConfig {
            applicationId "com.dsouchon.TicketingMiiD"
            minSdkVersion 16
            targetSdkVersion 21
           versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
            }
        }
        productFlavors {
        }
    }
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile files('libs/ksoap2-android-assembly-3.4.0-jar-with-   dependencies.jar')
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile 'com.google.android.gms:play-services:7.0.0'
       compile files('libs/CircleImageView-master/gradle/wrapper/gradle-    wrapper.jar')
       compile 'de.hdodenhof:circleimageview:2.0.0'
       compile 'com.jakewharton:process-phoenix:1.1.1'
     }

1 个答案:

答案 0 :(得分:0)

尝试以下可能对您有用。

如果您对扫描代码有开放意图,请指定代码格式,如下所示:

intent.putExtra("SCAN_FORMATS", "CODABAR");

以下是格式列表:

/** QR Code 2D barcode format. */
public static final BarcodeFormat QR_CODE = new BarcodeFormat("QR_CODE");

/** DataMatrix 2D barcode format. */
public static final BarcodeFormat DATA_MATRIX = new BarcodeFormat("DATA_MATRIX");

/** UPC-E 1D format. */
public static final BarcodeFormat UPC_E = new BarcodeFormat("UPC_E");

/** UPC-A 1D format. */
public static final BarcodeFormat UPC_A = new BarcodeFormat("UPC_A");

/** EAN-8 1D format. */
public static final BarcodeFormat EAN_8 = new BarcodeFormat("EAN_8");

/** EAN-13 1D format. */
public static final BarcodeFormat EAN_13 = new BarcodeFormat("EAN_13");

/** UPC/EAN extension format. Not a stand-alone format. */
public static final BarcodeFormat UPC_EAN_EXTENSION = new BarcodeFormat("UPC_EAN_EXTENSION");

/** Code 128 1D format. */
public static final BarcodeFormat CODE_128 = new BarcodeFormat("CODE_128");

/** Code 39 1D format. */
public static final BarcodeFormat CODE_39 = new BarcodeFormat("CODE_39");

/** Code 93 1D format. */
public static final BarcodeFormat CODE_93 = new BarcodeFormat("CODE_93");

/** CODABAR 1D format. */
public static final BarcodeFormat CODABAR = new BarcodeFormat("CODABAR");

/** ITF (Interleaved Two of Five) 1D format. */
public static final BarcodeFormat ITF = new BarcodeFormat("ITF");

/** RSS 14 */
public static final BarcodeFormat RSS14 = new BarcodeFormat("RSS14");

/** PDF417 format. */
public static final BarcodeFormat PDF417 = new BarcodeFormat("PDF417");

/** RSS EXPANDED */
public static final BarcodeFormat RSS_EXPANDED = new BarcodeFormat("RSS_EXPANDED");