Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ravi8x/barcode-reader
Android barcode reader using google vision library
https://github.com/ravi8x/barcode-reader
android android-library androidhive barcode-scanner barcodes google-vision-api
Last synced: 3 days ago
JSON representation
Android barcode reader using google vision library
- Host: GitHub
- URL: https://github.com/ravi8x/barcode-reader
- Owner: ravi8x
- License: bsd-3-clause
- Created: 2017-08-01T12:29:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-08T07:13:09.000Z (almost 4 years ago)
- Last Synced: 2024-12-23T22:10:08.312Z (10 days ago)
- Topics: android, android-library, androidhive, barcode-scanner, barcodes, google-vision-api
- Language: Java
- Size: 271 KB
- Stars: 294
- Watchers: 19
- Forks: 183
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Barcode Reader - Google Mobile Vision
===================
Android Barcode Reader library using **Google Mobile Vision.** This library is built on top of google mobile vision sample adding improvements and fixing few bugs.[ ![Download](https://api.bintray.com/packages/androidhive-info/maven/barcode-reader/images/download.svg) ](https://bintray.com/androidhive-info/maven/barcode-reader/_latestVersion)
[![Example](https://img.shields.io/badge/Example-Movie%20Tickets-green.svg)](https://www.androidhive.info/2017/07/android-implementing-preferences-settings-screen/)![Demo](https://user-images.githubusercontent.com/497670/29021175-41e613c4-7b82-11e7-8887-a6d8186aeca3.gif)
How to Use
-------------
1. Include the barcode reader dependency in app's **build.gradle**
```gradle
dependencies {
// google mobile vision
implementation 'com.google.android.gms:play-services-vision:11.0.2'// barcode reader
implementation 'info.androidhive:barcode-reader:1.1.5'
}
```2. Add the barcode reader fragment to your activity
```xml```
3. Implement your activity from
BarcodeReader.BarcodeReaderListener
and override the necessary methods.
```java
public class MainActivity extends AppCompatActivity implements BarcodeReader.BarcodeReaderListener {private BarcodeReader barcodeReader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barcodeReader = (BarcodeReader) getSupportFragmentManager().findFragmentById(R.id.barcode_fragment);
}@Override
public void onScanned(Barcode barcode) {
// play beep sound
barcodeReader.playBeep();
}@Override
public void onScannedMultiple(List list) {}
@Override
public void onBitmapScanned(SparseArray sparseArray) {}
@Override
public void onScanError(String s) {}
@Override
public void onCameraPermissionDenied() {
Toast.makeText(getApplicationContext(), "Camera permission denied!", Toast.LENGTH_LONG).show();
}
}
```Adding Barcode Reader in Fragment
----
In fragment the barcode reader can be added easily but the scanner listenerbarcodeReader.setListener()
has to
be set manually.Check the example fragment code in
BarcodeFragment.java
andBarcodeFragmentTestActivity.java
https://github.com/ravi8x/Barcode-Reader/tree/master/example/src/main/java/info/androidhive/barcodereader
Adding Scanner Overlay Scanning Indicator
----
The overlay animation indicator displays a horizontal line animating from top to bottom. This will be useful to to show some cool animation to indicate scanning progress.To use it, add the
info.androidhive.barcode.ScannerOverlay
on top of barcode reader fragment using Relative or Frame layout.
```xml
```
Additional Options
-------------
XML attribute for **Barcode Reader**
auto_focus
- boolean, turn on/off auto focus. Default istrue
use_flash
- boolean, turn on/off flash. Default isfalse
XML attribute for **Scanner Overlay** Indicator
square_width
- Width of transparent square
square_height
- Height of transparent square
line_color
- Horizontal line color
line_speed
- Horizontal line animation speed----
JAVA Methods
- **Play beep sound**
You can play the **beep** sound when the barcode is scanned. This code is usually called in
onScanned()
callback.
```java
@Override
public void onScanned(final Barcode barcode) {
Log.e(TAG, "onScanned: " + barcode.displayValue);
barcodeReader.playBeep();
});
}
```- **Change beep sound**
You can change the default **beep** sound by passing the file name. You beep file should be in project's **assets** folder.
```java
barcodeReader.setBeepSoundFile("shutter.mp3");
```- **Pause scanning**
The scanning can be paused by calling
pauseScanning()
method.
```java
barcodeReader.pauseScanning();
```- **Resume Scanning**
The scanning can be resumed by calling
resumeScanning()
method.
```java
barcodeReader.resumeScanning();
```## Know Issues
- Camera stream is not smooth. It's because of camera resolution.
- Sometimes screen turns black after Camera permission is granted.