2015-01-08 6 views
24

मैं अपने प्रोजेक्ट के लिए पुस्तकालय ZXing शामिल करने के लिए सभी इंटरनेट पर तलाश कर दिया गया है, और मैं इस ट्यूटोरियल पाया: http://blog.dihaw.com/integrating-zxing-in-your-android-app-as-standalone-scanner/बारकोड स्कैनिंग के लिए एंड्रॉइड स्टूडियो में जेएक्सिंग लाइब्रेरी को एकीकृत कैसे करें?

लेकिन जब मैं कहना है कि आप आर आयात मैं जोड़ने के लिए BeepManager के लिए जांच करने की आवश्यकता तक पहुँचने मेरी परियोजना में सभी प्रकार की त्रुटियां (यहां तक ​​कि मुख्य गतिविधि पर भी) कि यह आर

भी मुझे यह पाया गया कि यह एक https://github.com/journeyapps/zxing-android-embedded/blob/master/README.md है जो बहुत आसान लग रहा था क्योंकि यह स्वत: एकीकृत हो गया था, लेकिन जब मैं इसे पॉप करता हूं एक त्रुटि है कि यह फाइल नहीं मिल सका।

किसी भी मदद की सराहना की जाएगी :) मैं एंड्रॉइड स्टूडियो में नया हूं।

संपादित करें:

मैं अपने build.gradle को 2 विधि (Gradle सेटिंग्स के साथ एक) की सेटिंग जोड़ा गया है और 4 त्रुटि पॉप अप:

Error:Failed to find: com.embarkmobile:zxing-android-legacy:2.0.0 
Error:Failed to find: com.google.zxing:core:3.0.1 
Error:Failed to find: com.embarkmobile:zxing-android-integration:2.0.0 
Error:Failed to find: com.embarkmobile:zxing-android-minimal:2.0.0 

किसी भी मदद की?

--- उत्तर ---

इस समस्या को मैं Gradle पर ऑफलाइन काम को निष्क्रिय करने के लिए आवश्यक ठीक करने के लिए। एंड्रॉइड स्टूडियो की सेटिंग्स में जाएं> ग्रैडल> अनचेक 'ऑफ़लाइन काम' उसके बाद, आप जाने के लिए अच्छे हैं!

+0

विशिष्ट त्रुटि संदेश उपयोगी होगा। आप इसे अलग करने के लिए ब्लॉकक्वाट प्रकार मार्कडाउन स्वरूपण ('>' लाइनों की शुरुआत में) का उपयोग कर सकते हैं और सुनिश्चित कर सकते हैं कि आपका प्रश्न पठनीय है। परिवर्तन करने के लिए अपने प्रश्न के नीचे [संपादित करें लिंक] (https://stackoverflow.com/posts/27851512/edit) का उपयोग करें। –

+0

बारकोड पढ़ने का एकमात्र तरीका ZXing नहीं है। 2016 तक, [एंड्रॉइड बारकोड एपीआई] (http://stackoverflow.com/questions/6327483/implement-bar-code-scanner-in-android/38881708#38881708) का उपयोग करना बहुत आसान है। –

उत्तर

36

आप जोड़ने की जरूरत है अपने build.gradle फ़ाइल में निम्नलिखित:

repositories { 
    mavenCentral() 

    maven { 
     url "http://dl.bintray.com/journeyapps/maven" 
    } 
} 

dependencies { 
    // Supports Android 4.0.3 and later (API level 15) 
    compile 'com.journeyapps:zxing-android-embedded:[email protected]' 

    // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions. 
    // If you only plan on supporting Android 4.0.3 and up, you don't need to include this. 
    compile 'com.journeyapps:zxing-android-legacy:[email protected]' 

    // Convenience library to launch the scanning and encoding Activities. 
    // It automatically picks the best scanning library from the above two, depending on the 
    // Android version and what is available. 
    compile 'com.journeyapps:zxing-android-integration:[email protected]' 

    // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier. 
    // This mostly affects encoding, but you should test if you plan to support these versions. 
    // Older versions e.g. 2.2 may also work if you need support for older Android versions. 
    compile 'com.google.zxing:core:3.0.1' 
} 

मेरे build.gradle फ़ाइल इस तरह:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "com.myapplication2" 
     minSdkVersion 16 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

repositories { 
    mavenCentral() 

    maven { 
     url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/" 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    // Supports Android 4.0.3 and later (API level 15) 
    compile 'com.embarkmobile:zxing-android-minimal:[email protected]' 

    // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions. 
    // If you only plan on supporting Android 4.0.3 and up, you don't need to include this. 
    compile 'com.embarkmobile:zxing-android-legacy:[email protected]' 

    // Convenience library to launch the scanning and encoding Activities. 
    // It automatically picks the best scanning library from the above two, depending on the 
    // Android version and what is available. 
    compile 'com.embarkmobile:zxing-android-integration:[email protected]' 

    // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier. 
    // This mostly affects encoding, but you should test if you plan to support these versions. 
    // Older versions e.g. 2.2 may also work if you need support for older Android versions. 
    compile 'com.google.zxing:core:3.0.1' 
} 

कोड here है।

इसके अलावा, के लिए कि यह कैसे उपयोग करने के लिए, कृपया Stackoverflow here

पर मेरा उत्तर उल्लेख यह विधि और भी सरल कोड है कि मैं परीक्षण किया है शामिल हैं।

+0

मैंने उन सेटिंग्स को मेरे build.gradle और 4 त्रुटि पॉप अप में जोड़ा: त्रुटि: ढूंढने में विफल: com.embarkmobile: zxing-android-legacy: 2.0.0 त्रुटि: ढूंढने में विफल: com.google.zxing: core : 3.0.1 त्रुटि: ढूंढने में विफल: com.embarkmobile: zxing-android-angration: 2.0.0 त्रुटि: ढूंढने में विफल: com.embarkmobile: zxing-android-minimal: 2.0.0 कोई मदद? यह वही त्रुटि है जो –

+0

से पहले हुई थी इसे हल किया गया! मैं एक उत्तर –

+0

मदद करने के लिए खुशी होगी, चीयर्स! – bjiang

16

का संस्करण 3 के रूप में ZXing-एंड्रॉयड एम्बेडेड आप केवल अपने build.gradle फाइल करने के लिए इन जोड़ने की जरूरत:

repositories { 
    jcenter() 
} 

dependencies { 
    compile 'com.journeyapps:zxing-android-embedded:[email protected]' 
    compile 'com.google.zxing:core:3.2.0' 
} 

में चरणों का पालन करें: https://github.com/journeyapps/zxing-android-embedded/

अब यह भी साथ पोर्ट्रेट मोड के लिए अनुमति देता है IntentIntegrator में सरल परिवर्तन, और विचारों को अनुकूलित करने के आसान तरीके।

+0

हाय, भाई। क्या आपने एम्बेडेड ZXing में CompoundBarcodeView का उपयोग किया था? –

+0

हां। मैं दृश्यदर्शी की दृश्यता के साथ शुरूआत के रूप में शुरू करता हूं और एक बटन क्लिक होने पर दृश्य में बदल जाता है, जो एक स्कैन के लिए डीकोड सिंगल भी कॉल करता है। इस तरह से दृश्य दिखाता है कि कैमरा क्या देखता है, लेकिन दृश्यदर्शी की लाल रेखा और पीले रंग के पैच के बिना, जब तक कि उपयोगकर्ता वास्तव में कैप्चर नहीं करना चाहता। लेकिन निश्चित रूप से, मुझे अपने ऐप के लिए यही चाहिए, आपको इसे पूरे समय दृश्यमान और कैप्चर करने की आवश्यकता हो सकती है। –

+0

यह नया "स्वीकृत उत्तर" होना चाहिए! –

1

मैं इसे इस के साथ काम किया है:

repositories { mavenCentral() 
    maven { url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/" } 
} 

compile 'com.google.zxing:core:3.2.1' 
compile 'com.embarkmobile:zxing-android-minimal:[email protected]' 
compile 'com.embarkmobile:zxing-android-integration:[email protected]' 

मैं IntentIntegrator

IntentIntegrator integrator = new IntentIntegrator(getActivity()); 
integrator.forSupportFragment(this).initiateScan(); 

का उपयोग कर requestCode IntentIntegrator.REQUEST_CODE

3

के साथ वापस आ बारकोड या के लिए ZXing एकीकृत करने के लिए सबसे आसान तरीका आता है की सलाह देते हैं क्यूआर स्कैनिंग।

पूर्ण संदर्भ के लिए: Scan Barcode ZXing Android

निर्भरता

compile 'me.dm7.barcodescanner:zxing:1.9' 

ScanActivity में जोड़े

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import com.google.zxing.Result; 

import me.dm7.barcodescanner.zxing.ZXingScannerView; 

public class ScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{ 

    private ZXingScannerView mScannerView; 

    @Override 
    public void onCreate(Bundle state) { 
     super.onCreate(state); 
     mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view 
     setContentView(mScannerView);    // Set the scanner view as the content view 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. 
     mScannerView.startCamera();   // Start camera on resume 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     mScannerView.stopCamera();   // Stop camera on pause 
    } 

    @Override 
    public void handleResult(Result rawResult) { 
     // Do something with the result here 
     // Log.v("tag", rawResult.getText()); // Prints scan results 
     // Log.v("tag", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.) 

     MainActivity.tvresult.setText(rawResult.getText()); 
     onBackPressed(); 

     // If you would like to resume scanning, call this method below: 
     //mScannerView.resumeCameraPreview(this); 
    } 
} 
संबंधित मुद्दे

 संबंधित मुद्दे