Software Development Kits

Software Development Kits

GS-SDK1
The Generalscan SDK Development Kit is a SDK software package developed by Generalscan for third-party software developers using the Generalscan full range of Bluetooth scanners on Android smartphone platforms. This software package provides a variety of low-level functions, so that users do not need to understand complex Bluetooth protocols and communication mechanisms of various USB devices, so that the Generalscan Bluetooth scanner can be easily and directly embedded into your application.
The Generalscan SDK development kit provides a variety of software functions, including Bluetooth SPP communication, pairing, data transmission, Bluetooth device name modification, barcode function setting, hardware ID reading, DES encryption algorithm and decryption algorithm, standby sleep time setting.
The source code of Generalscan SDK is maintained on GitHub, users can download it by themselves.

Import SDK to Android Studio project

Import SDK to Android Studio project

  1. Copy the SDK aar file to app/libs
  2. Add the flatDir setting Gradle configuration to your Android project. In your root build.gradle file:
allprojects { 
repositories 
{
jcenter()
flatDir { dirs 'libs' }  // add flatDir setting
} 
}

  1. Open app level build.grdle file and add .aar file and kotlin runtime

    dependencies 
    { 
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.10'     
    implementation(name:'generalscan-sdk-1.0', ext:'aar')
    }
  1. Add the follow permissions into manifest.xml

    <!-- Permission For Bluetooth -->
    <uses-permission android:name="android.permission.BLUETOOTH" /> 
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <!-- Permissions for USB Host (Scan Buddy) -->
    <uses-feature android:name="android.hardware.usb.host" android:required="true" />
    <!-- Show Alert Dialog in Service -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

  1. Add the follow service declarations into manifest.xml
<service android:name="com.generalscan.scannersdk.core.session.bluetooth.
service.BluetoothConnectService"
android:enabled="true"    
android:exported="true" />
<service android:name="com.generalscan.scannersdk.core.session.usbhost.
service.UsbHostService"    
android:enabled="true" 
android:exported="true" /> 

<service android:name="com.generalscan.scannersdk.core.session.usbhost.
service.FloatingScanButtonService"       
android:enabled="true"    
android:exported="true" />


Interacting with a Bluetooth scanner

Interacting with a Bluetooth scanner

  1. Turn on Bluetooth
  2. Start Bluetooth session after activity created

    BluetoothConnectSession mBluetoothConnectSession = new BluetoothConnectSession(this);
    
    //Setup session listener
    
    mBluetoothConnectSession.setSessionListener( 
    new SessionListener()
    {
    //When session is ready
    @Override
    public void onSessionReady(IConnectSession iConnectSession) { 
    //TODO:to connect the device here or later
    } 
    //When session service initialization timeout
    @Override
    public void onSessionStartTimeOut(IConnectSession iConnectSession) {
    //TODO:show error message
    } 
    }
    ); 
    mBluetoothConnectSession.startSession();

Set the receiver to read the barcode

Set the receiver to read the barcode

Setup listenter to ceceieve data

mBluetoothConnectSession.setConnectListener( 

new CommunicateListener() 

{  

//Bluetooth device disconnected

@Override

public void onDisconnected()

{ showMessage("Device has been disconnected"); 

}



     

//Bluetooth device connect failed

@Override

public void onConnectFailure(String errorMessage) {   

showMessage(errorMessage); 

}  



//Bluetooth device connect success

@Override

public void onConnected() {    

showMessage(R.string.scanner_connect_success); 

}  





//Scanner data received

@Override

public void onDataReceived(String data) { mTxtReceiveData.append(data); 

}  





//Bluetooth command callback

@Override

public void onCommandCallback(String name, String data) { mTxtReceiveData.append("$name:$data"); 

}  





//Battery data receive

@Override

public void onBatteryDataReceived(String voltage, String percentage) { mTxtReceiveData.append(voltage + ":" + percentage); 

}  





//Scanner command timeout

@Override

public void onCommandNoResponse(String errorMessage) { 

}  





//Data receive error

@Override

public void onRawDataReceiveError(String errorMessage, String source) { 

}  





//Raw data receive

@Override

public void onRawDataReceived(byte data) { 

}

}

 );


Bluetooth pairing, connection, stop session

Bluetooth pairing, connection, stop session

Pair Bluetooth device
Connect Bluetooth device

BluetoothAdapter mBluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
BluetoothDevice device = BluetoothAdapter.getRemoteDevice(mSelectedDeviceAddress);
mBluetoothConnectSession.setBluetoothDeviceToConnect(device); mBluetoothConnectSession.connect();

Stop Bluetooth session after activity is destroy
//Send current bluetooth session
mBluetoothConnectSession.endSession();


















































 
 

Download From Google Play

 
GS-SDK1