Integrating the ZXing library directly into my Android application

后端 未结 17 1639
[愿得一人]
[愿得一人] 2020-11-22 04:35

I\'m writing this in mere desperation :) I\'ve been assigned to make a standalone barcode scanner (as a proof of concept) to an Android 1.6 phone.

For this i\'ve dis

17条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 05:26

    I tried all possible ways to achieve this and then I discovered Minified version of xZing by JourneyApps. I have ported that for eclipse and shared on GitHub.

    If you are using eclipse use this project:-

    https://github.com/hiteshsahu/XZing-Barcode-Scanner-Minified-Eclipse

    If you are using Studio use this project :-

    https://github.com/journeyapps/zxing-android-embedded

    Advantages

    1. Inbuilt Barcode scanner in your App do not required to install third party apps using playstore.

    2. You dont need to get confused between Core,Android client etc jars simply drop this packages and relevent layouts in your project and you are good to go. Only Jar required is com.google.zxing:core:3.2.0 which you can download from

      http://mvnrepository.com/artifact/com.google.zxing/core/3.2.0

    3. No need to add tons of packages see images below for comparison

    Before :-

    After :-

    1. Most important part is they are highly customizable ie. you can add flash light, use it in fragment and support orientation change.

    2. You can use this Capture activity in Cordova App for barcode scanneing.

    your capture activity in app manifest would look like this

      
                
                    
    
                    
                
            
    

    and plugin will look like this

    public class BarcodeScanner extends CordovaPlugin {
        public static final int REQUEST_CODE = 0x0ba7c0de;
    
        private static final String SCAN = "scan";
        private static final String CANCELLED = "cancelled";
        private static final String FORMAT = "format";
        private static final String TEXT = "text";
        private static final String SCAN_INTENT = "com.google.zxing.client.android.SCAN";
    
        private static final String LOG_TAG = "BarcodeScanner";
    
        private CallbackContext callbackContext;
    
        /**
         * Constructor.
         */
        public BarcodeScanner() {
    
    
        }
    
        /**
         * Executes the request.
         *
         * This method is called from the WebView thread. To do a non-trivial amount of work, use:
         *     cordova.getThreadPool().execute(runnable);
         *
         * To run on the UI thread, use:
         *     cordova.getActivity().runOnUiThread(runnable);
         *
         * @param action          The action to execute.
         * @param args            The exec() arguments.
         * @param callbackContext The callback context used when calling back into JavaScript.
         * @return                Whether the action was valid.
         *
         * @sa https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaPlugin.java
         */
        @Override
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
            this.callbackContext = callbackContext;
            if (action.equals(SCAN)) {
                scan(args);
            } else {
                return false;
            }
            return true;
        }
    
        /**
         * Starts an intent to scan and decode a barcode.
         */
        public void scan(JSONArray args) {
            Intent intentScan = new Intent(SCAN_INTENT);
            intentScan.addCategory(Intent.CATEGORY_DEFAULT);
    
            // add config as intent extras
            if(args.length() > 0) {
    
                JSONObject obj;
                JSONArray names;
                String key;
                Object value;
    
                for(int i=0; i

    Happy Integration !!

提交回复
热议问题