1
votes

I am creating an android app that will allow you to scan food and view the name, best before date, calories, nutritional information.

I have implemented ZXing barcode scanner using this youtube tutorial : https://www.youtube.com/watch?v=otkz5Cwdw38

But I don't know how to specify what data I want to pull when the barcode is scanned. I have two tables food and nutritional information and I want to be able to add to these when the user clicks okay after scanning the barcode.

I am really new to this so any help would be greatly appreciated.

1
you want scan only barcode or QR code also???? - Dilip

1 Answers

0
votes

Add the following dependency to your build.gradle file.

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

Simple Usage

1.) Add camera permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />

2.) A very basic activity would look like this:

public class SimpleScannerActivity extends Activity 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.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}