Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.69 KB

README.md

File metadata and controls

39 lines (30 loc) · 1.69 KB

Overview

This is the library modified from the original ZXing Project. The code is not modified in any way but is just compiled into a library so that the end user doesn't have to download the scanner app separately.

Adding the library

Add this line (if not already present there) in the project's build.gradle file

repositories {
    jcenter()
}

Add this statement in the dependencies block of app's build.gradle file

compile 'com.tarun0.zxing-standalone:zxing-standalone:1.0.0'

#Usage Send an intent when you need to scan, like on clicking on a button

Intent intent = new Intent(getApplicationContext(),CaptureActivity.class);
            intent.setAction("com.google.zxing.client.android.SCAN");
            intent.putExtra("SAVE_HISTORY", false);
            startActivityForResult(intent, 0);

Handle the result from the intent by overriding onActivityResult

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = data.getStringExtra("SCAN_RESULT");
                Log.d(TAG, "contents: " + contents);
            } else if (resultCode == RESULT_CANCELED) {
                Log.d(TAG, "RESULT_CANCELED");
            }
        }
    }

Notes