How to integrate Zxing Barcode Scanner without installing the actual zxing app (cannot resolve symbol: .android.CaptureActivity)?

前端 未结 8 1561
我寻月下人不归
我寻月下人不归 2020-12-07 10:04

I want to integrate zxing scanner into my app without needed of external application (zxing scanner from play store). This is my code

Button scan = (Button)         


        
8条回答
  •  不知归路
    2020-12-07 10:28

    I am really late but I wish to reply on this for someone else to be helped later. This is not to say that the above methods and solution are wrong, Its just an additional info so, for the developer he/she will choose the better way. It is good to have thousand way to go than having one.

    So, let's start into our gradle and add

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

    Calling the module like (eg: on button click):

    IntentIntegrator integrator = new IntentIntegrator(Home.this);
                integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
                integrator.setPrompt("Scan Code");
                integrator.setCameraId(0);
                integrator.setBeepEnabled(true);
                integrator.setBarcodeImageEnabled(false);
                integrator.initiateScan();
    

    Get the results like:

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

    }

    For more info you can check the link https://github.com/pethoalpar/ZxingExample

提交回复
热议问题