Home » Android » Barcode scanner using zking libary [on hold]

Barcode scanner using zking libary [on hold]

Posted by: admin November 1, 2017 Leave a comment

Questions:

I am not able to scan college ID barcode, but can scan if I generate barcode on device.
This is my MainActivity.java

    public class MainActivity extends AppCompatActivity {

    private Button scanbutton;
    EditText editRegistration;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editRegistration = (EditText) findViewById(R.id.editText_registration);

        scanbutton = (Button) findViewById(R.id.scanbutton);
        final Activity activity = this;
        scanbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IntentIntegrator integrator = new IntentIntegrator(activity);
                integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
                integrator.setPrompt("scan");
                integrator.setCameraId(0);
                integrator.setBeepEnabled(true);
                integrator.setBarcodeImageEnabled(true); //true
                integrator.initiateScan();
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){

        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null)
            if (result.getContents() == null)
                Toast.makeText(this, "scanning cancellled", Toast.LENGTH_LONG).show();
            else
                 editRegistration.setText(result.getContents());


        else

            super.onActivityResult(requestCode, resultCode, data);
    }

 }
Answers: