Source link:


Barcode Scanner supported by Mobile Vision Api

Update 2.0.0

  • Bug fixes and Better Performance
  • Capturing scanned screen
  • support two or more barcode format
  • release a barcode detector
  • use the front camera for scanning
  • immediate refresh functionality
  • update to 11.0.4 mobile vision sdk

adding as a dependency

on JCenter

dependencies {

 compile 'xyz.belvi.mobilevision:barcodescanner:2.0.0'


on JitPack

Step 1.

Add the JitPack repository to your build file in your root build.gradle at the end of repositories:

allprojects {
  repositories {

maven {
 url "" 
Step 2.

Add the dependency

dependencies {

compile 'com.github.KingsMentor:MobileVisionBarcodeScanner:2.0.0' 

Supported Attributes

  <attr name="gvb_show_text" format="boolean" />

<attr name="gvb_draw" format="boolean" />

<attr name="gvb_multiple" format="boolean" />

<attr name="gvb_touch" format="boolean" />

<attr name="gvb_auto_focus" format="boolean" />

<attr name="gvb_flash" format="boolean" />

<attr name="gvb_rect_colors" format="reference" />

<attr name="gvb_camera_facing" format="enum">

 <enum name="back" value="0"></enum>

 <enum name="front" value="0"></enum>


<attr name="gvb_code_format">

 <flag name="all_format" value="0"></flag>

 <flag name="code_128" value="1"></flag>

 <flag name="code_39" value="2"></flag>

 <flag name="code_93" value="4"></flag>

 <flag name="code_bar" value="8"></flag>

 <flag name="data_matrix" value="16"></flag>

 <flag name="ean_13" value="32"></flag>

 <flag name="ean_8" value="64"></flag>

 <flag name="itf" value="128"></flag>

 <flag name="qr_code" value="256"></flag>

 <flag name="upc_a" value="512"></flag>

 <flag name="upc_e" value="1024"></flag>

 <flag name="pdf417" value="2028"></flag>

 <flag name="aztec" value="4029"></flag>


What are the attibutes for :

  • gvb_draw - enable rect drawn around codes when scanning
  • gvb_multiple - want the camera to return as many qr codes that was scanned. This works with gvb_touch attribute. it only returns result when the screen is clicked or touch
  • gvb_touch - turn on touch listener for screen
  • gvb_auto_focus - support auto focus
  • gvb_flash - turn on flash
  • gvb_rect_colors - arrays of colors to draw rect
  • gvb_code_format - barcode format that should be support . Default is all_format

Note these attributes can also be initialised from java code . We would look into that later

Using the Mobile Vision Powered Camera.

Step 1 - Add layout in xml:








 app:gvb_rect_colors="@array/rect_color" />

and this is rect_color in colors.xml

<?xml version="1.0" encoding="utf-8"?> <resources>

<color name="color_green">#14808d</color>
  <color name="color_brown">#343838</color>
  <color name="color_orange">#f38a32</color>
  <color name="color_blue">#1479b7</color>
  <color name="divider_grey">#e4e4e5</color>

<array name="rect_color">





  </array> </resources> 
Step 2 - Initialise in java
BarcodeCapture barcodeCapture = (BarcodeCapture) getSupportFragmentManager().findFragmentById(barcode);

also make sure your java class implements BarcodeRetriever

public class MainActivity extends AppCompatActivity implements BarcodeRetriever {

 // for one time scan
  public void onRetrieved(final Barcode barcode) {

Log.d(TAG, "Barcode read: " + barcode.displayValue);

runOnUiThread(new Runnable() {


 public void run() {

  AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)

 .setTitle("code retrieved")





// for multiple callback
  public void onRetrievedMultiple(final Barcode closetToClick, final List<BarcodeGraphic> barcodeGraphics) {

runOnUiThread(new Runnable() {


 public void run() {

  String message = "Code selected : " + closetToClick.displayValue + "\n\nother " +

 "codes in frame include : \n";

  for (int index = 0; index < barcodeGraphics.size();
 index++) {

Barcode barcode = barcodeGraphics.get(index).getBarcode();

message += (index + 1) + ". " + barcode.displayValue + "\n";


  AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)

 .setTitle("code retrieved")





  public void onBitmapScanned(SparseArray<Barcode> sparseArray) {

// when image is scanned and processed

  public void onRetrievedFailed(String reason) {

// in case of failure

as you can see, BarcodeRetriever interface handles the callback when a code is scanned successfully based on specified attributes.


  • To scan a bitmap,
BarcodeBitmapScanner.scanBitmap(this, bitmap, Barcode.ALL_FORMATS, this);
  • Set attributes from java - Use the BarcodeCapture instance to reference setter methods
  • Stop barcode detection
  • Retrieve Image of Scanned Screen. This will return a Camera object that you can use to retrieve other neccessary information:
  • Refresh - make update to barcodeCapture and use refresh for immediate screen update.







  .setCameraFacing(frontCam.isChecked() ? CameraSource.CAMERA_FACING_FRONT : CameraSource.CAMERA_FACING_BACK)



Resources and Credits


Contributions are welcome. Generally, contributions are managed by issues and pull requests.

  1. Submit an issue describing your proposed fix or feature.
  2. If your proposed fix or feature is accepted then, fork, implement your code change.
  3. Ensure your code change follows the accepted code style and structure.
  4. Ensure your code is properly tested.
  5. Ensure your commits follow the accepted commit message style
  6. Submit a pull request.

#License The MIT License (MIT). Please see the License File for more information.


similarLoadingView is a custom loading view for Android. It is very easy to use and customize. It draws your drawable on canvas with stylish design.

PseudoNet is a app which integrates various online services into a single app and provides a user interface to use those services offline using SMS.

Mediation advertise helper for ADMOB, FACEBOOK - Support Native, Banner, Backpress Dialog, Front AD.

A demo that shows how to implement chained spring animation on Android.

An Android frame In order to support single Activity + multi Fragment framework.

Abstraction to build adapters with dynamic/variable view types count for Android application. It eliminates the need to manually define view types. Makes code readable and actually share view types across multiple screens (no need to write a new adapter, or add view types handling in one base adapter with endless switch statement).


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes