Integrating the ZXing library directly into my Android application

后端 未结 17 1711
[愿得一人]
[愿得一人] 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:18

    Much Easier approach.

    Just include dependency in your app level gradle file

    compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
    compile 'com.google.zxing:core:3.2.0'  
    

    Define one button in your xml file and and write below code in Java file in OnCreate()and inside the OnClick listener of button

    new IntentIntegrator(this).initiateScan();
    

    And write below code after OnCreate() of the Java file

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result != null) {
            if(result.getContents() == null) {
                Log.d("MainActivity", "Cancelled scan");
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                Log.d("MainActivity", "Scanned");
                String st_scanned_result = result.getContents();
                Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
    
            }
        }
    
    }
    

提交回复
热议问题