2017-02-08 142 views
0

您好已成功將Zxing掃描器集成到我的應用程序中,但是我遇到的問題是它不想掃描條碼,但它完美地掃描了二維碼。當我單獨打開Zxing應用程序時,條形碼掃描器就可以工作。當我從我正在構建的應用程序啓動它時,它不起作用。有沒有人有過這個問題,並找到解決方案?Zxing條碼掃描器不掃描條碼時與android應用程序結合

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' 
    } 
+0

調試代碼你發現了什麼? –

+0

分享你的代碼和build.gradle? –

+0

@AbhijitChakra我在調試中發現了任何東西。 –

回答

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"); 
+0

坦克。這最後一個工作很好。我必須將其更改爲「CODE_39」 –