Skip to content

A Simple helper for GeneralScan Barcode scanner's Bluetooth feature. This helper is just based on the library which can be found here http://www.generalscan.com/en-us/gs-sdk-en.php

License

Notifications You must be signed in to change notification settings

edwnmrtnz/GeneralScanBarcodeScanner

Repository files navigation

GeneralScanBarcodeScanner

Summary

A Simple helper for GeneralScan barcode scanner.

Prerequisites

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
    repositories {
	    ...
	    maven { url 'https://jitpack.io' }
	}
}

Dependency

Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):

dependencies {
	compile 'com.github.edwnmrtnz:GeneralScanBarcodeScanner:v0.1.0'
}

Usage

Create a class that extends Application and create a newInstance of BarcodeScannerHelper.

public class ScannerApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        BarcodeScannerHelper.newInstance(this);
    }
}

Inside your manifest file, add the following permissions:

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

<!-- Show Alert Dialog in Service -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Add this Service inside the block of your manifest.

<service android:name="com.generalscan.bluetooth.connect.ATService"
         android:enabled="true"/>

To connect to your barcode scanner, select your device through

BarcodeScannerHelper.getInstance().selectScanner();

After selecting a device, call connectScanner from BarcodeScannerHelper and implment the BarcodeScannerConnectionListner.

BarcodeScannerHelper.getInstance().connectScanner(new BarcodeScannerConnectionListener() {
          @Override
          public void onDisconnected() {
              toast("Connection failed!");
          }

          @Override
          public void onConnected() {
              toast("Connection success!");

          }
      });

To start receiving data, you need to start the broadcast receiver. Just call startBarcodeBroacastReceiver() of the BarcodeScannerHelper and implement a BarcodeDataListener. You can call this inside onCreate() or onStart() of your activity.

BarcodeScannerHelper.getInstance().startBarcodeBrodcastReceiver(context);
BarcodeScannerHelper.getInstance().setOnBarcodeDataListener(new BarcodeDataListener() {
    @Override
    public void onDataReceived(String data) {
      toast("Scanned data: " + data);
    }
});

To stop receiving data, just call stopBarcodeBroadcastReceiver(). You can call this inside onStop() or onDestroy() of your activity.

BarcodeScannerHelper.getInstance().stopBarcodeBroadcastReceiver(context);

About

A Simple helper for GeneralScan Barcode scanner's Bluetooth feature. This helper is just based on the library which can be found here http://www.generalscan.com/en-us/gs-sdk-en.php

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages