Coder Social home page Coder Social logo

androidvisionqrreader's Introduction

QR Reader based on Android Vision API

This is a small sample library that scans QR Codes using the new Mobile Vision API for Android included in latest release of Google Play Services, which allows you to avoid using external libraries.

Feel free to use this project as a small sample of how to use this API for scanning QR Codes and customize it however you want ;)

Integration instructions

Requirements

  • Android SDK version 9 or later.

Setup

If you use gradle, then add the following dependency:
compile project(':AndroidVisionQRReader')
Or you can put the AndroidVisionQRReader.aar file inside libs directory and add the following dependency:
repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    compile(name:'AndroidVisionQRReader', ext:'aar')
}
If you use something other than gradle, then:
  1. Edit AndroidManifest.xml. We're going to add a few additional items in here:

    <uses-sdk android:minSdkVersion="9" />
  2. Also in your <manifest> element, make sure the following permissions and features are present:

    <uses-permission android:name="android.permission.CAMERA" />
    
    <meta-data
        android:name="com.google.android.gms.vision.DEPENDENCIES"
        android:value="barcode" />
  3. Within the <application> element, add activity entries:

    <!-- Activities responsible for scan QR code -->
    <activity android:name="com.gnzlt.AndroidVisionQRReader.QRActivity" />

Sample code (See the QRTest App for an example)

First, we'll assume that you're going to launch the request from a button, and that you've set the button's onClick handler in the layout XML via android:onClick="requestQRCodeScan". Then, add the method as:

public void requestQRCodeScan(View v) {
    Intent qrScanIntent = new Intent(this, QRActivity.class);
    startActivityForResult(qrScanIntent, QR_REQUEST);
}

Next, we'll override onActivityResult() to get the request result.

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

        if (requestCode == QR_REQUEST) {
            if (resultCode == RESULT_OK) {
                String qrData = data.getStringExtra(QRActivity.EXTRA_QR_RESULT);
                // do something with the QR data String
            } else {
                mResultTextView.setText("Error");
            }
        }
    }

License

    Copyright (C) 2015 Gonzalo Toledano

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

androidvisionqrreader's People

Contributors

gnzlt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.