GENERALSCAN蓝牙扫描器软件开发包
Software Development Kits

Generalscan SDK 开发包
Software Development Kits

GS-SDK1
Generalscan SDK 开发包是Generalscan为第三方软件开发商在安卓智能手机平台使用Generalscan全系列蓝牙扫描器开发的SDK软件包。该软件包提供各种底层功能,使用户无需了解复杂的蓝牙协议以及各种USB设备的通信机制,从而简单直接的将Generalscan的蓝牙扫描器嵌入到您的应用中。
Generalscan SDK开发包提供了多种软件功能,其中包括蓝牙SPP通讯,配对,数据传输,蓝牙设备名称的修改,条码功能的设置,硬件ID的读取,DES加密算法和解密算法,待机休眠时间的设定等功能
Generalscan SDK 源代码在GitHub上维护,用户可以自行下载。

图标库-01

导入SDK到Android Studio项目

  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" />


图标库-02

与蓝牙扫描器交互

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

    BluetoothConnectSession mBluetoothConnectSession = new BluetoothConnectSession(this);
    
    //Setup session listener
    //设置 Session 监听
    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();

图标库-03

设置接收器读取条码

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) { 
}
}
 );

图标库-04

蓝牙配对、连接、停止会话

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();
























































谷歌市场App免费下载
Generalscan SDK

 
GS-SDK1