FeasyBlue SDK For Android
SDK Resource Kit Download
SDK Access Documents
SDK Version |
Writing Date |
Author |
---|---|---|
V3.3.1 |
2024/4/13 |
Chang Jigang |
Access method
Extract the SDK, then drag all the extracted files into the project.
Permission Request
To use the SDK, it is necessary to dynamically obtain location permissions. Turn on the phone’s location and Bluetooth in order to use it normally (For Android 6.0 or above, user needs to have dynamic location permissions and turn on the phone’s location, if it is not turned on, the phone will not be able to scan the BLE device due to the limitation of Android.)
The following permissions need to be added to AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
// Android 12 requires the following permissions
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
// Need to import Kotlin collaborative environment
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
Iitialization
BLE Initialization
// getInstance (context) and initialize() only need to be executed once, and other subsequent activities that need to use FscBleCentralApi can directly use FscSppCentralApiImp. getInstance()
FscBleCentralApi sFscBleCentralApi = FscBleCentralApiImp.getInstance(context);
sFscBleCentralApi.initialize();
SPP initialization
// getInstance (context) and initialize() only need to be executed once, and other subsequent activities that need to use FscSppCentralApi can directly use FscSppCentralApiImp. getInstance()
FscSppCentralApi sFscSppCentralApi = FscSppCentralApiImp.getInstance(context);
sFscSppCentralApi.initialize();
Interface statistics
BLE interface
/**
* Set callback
* @param callback
*/
void setCallbacks(FscBleCentralCallbacks callback);
/**
* Obtain the MTU value of the last connected device
* @return mtu
*/
int getMtu();
/**
* Get the MTU value of the specified device
* param address
* @return mtu
*/
int getMtu(String address);
/**
* Obtain the current maximum number of packets sent per last connected device
* @return
*/
int getMaximumPacketByte();
/**
* Get the current maximum number of packets sent per specified device
* param address
* @return
*/
int getMaximumPacketByte(String address);
/**
* Set the final connected feature data
* @param ch
* @param properties
* @return
*/
boolean setCharacteristic(BluetoothGattCharacteristic ch, int properties);
/**
* Set feature data for specified devices
* @param address
* @param ch
* @param properties
* @return
*/
boolean setCharacteristic(String address, BluetoothGattCharacteristic ch, int properties);
/**
* Read information on specified feature values
* @param address
* @param ch
* @return
*/
boolean read(String address, BluetoothGattCharacteristic ch);
/**
* Get services for specified devices
* @param address
*/
List<BluetoothGattService> getBluetoothGattServices(String address);
/**
* Set the MTU of the last connected device
* @param mtu
*/
@RequiresApi(value = Build.VERSION_CODES.LOLLIPOP)
void requestMtu(int mtu);
/**
* Set the MTU for the specified device
* @param address
* @param mtu
*/
@RequiresApi(value = Build.VERSION_CODES.LOLLIPOP)
void requestMtu(String address, int mtu);
/**
* Binding devices
*/
void createBond();
/**
* Check dfu File
* @param dfuFile dfu file
* @return {@link DfuFileInfo}
*/
DfuFileInfo checkDfuFile(byte[] dfuFile);
SPP Interface
/**
* Set callback
* @param callback
*/
void setCallbacks(FscSppCentralCallbacks callback);
/**
* Open the SDP service and wait for the device to connect
*/
void openSdpService();
/**
* Turn off SDP service and wait for device connection
*/
void closeSdpService();
/**
* Check upgrade files
* @param dfuFile
# @return
*/
DfuFileInfo checkDfuFile(byte[] dfuFile);
Common Interface
/**
* If display logs
* @param isEnableLog
*/
void isShowLog(boolean isEnableLog);
/**
* Initialization
* @return {@link boolean} Initialization result
*/
boolean initialize();
/**
* Is Bluetooth enabled
* @return {@link boolean} Bluetooth switch status
*/
boolean isEnabled();
/**
* Delete specified device pairing records
* @return {@link boolean} Whether the deletion was successful
*/
boolean clearDevice(String address);
/**
* Connect
* @param address
*/
void connect(String address);
/**
* Parameter modification connection (AT command mode)
* @param address
*/
void connectToModify(String address);
/**
* Air upgrade connection
* @param address
* @param dfuFile
* @param reset
*/
void connectToOTAWithFactory(String address, byte[] dfuFile, boolean reset);
/**
* Disconnect the last connected device
*/
void disconnect();
/**
* Disconnect the specified device
* @param address
*/
void disconnect(String address);
/**
* Get bound devices
* @return {@link FscDevice}
*/
List<FscDevice> getBondDevices();
/**
* Start scanning
*/
void startScan();
/**
* Stop scanning
*/
void stopScan();
/**
* Is there any device connected
* @return
*/
boolean isConnected();
/**
* Query connection status through device address
* @param address
* @return
*/
boolean isConnected(String address);
/**
* Send data to the last connected device
* @param data
* @param sendInterval
* @return
*/
boolean send(String data, Long sendInterval);
/**
* Send information to designated devices
* @param address
* @param data
* @param sendInterval
* @return
*/
boolean send(String address, String data, Long sendInterval);
/**
* Send data to the last connected device
* @param packet
* @param sendInterval
* @return
*/
boolean send(byte[] packet, Long sendInterval);
/**
* Send information to designated devices
* @param address
* @param data
* @param sendInterval
* @return
*/
boolean send(String address, byte[] packet, Long sendInterval);
/**
* Generate a test file of the specified size and send it to the last connected device
* @param size
* @param sendInterval
* @return
*/
boolean sendFile(int size, Long sendInterval);
/**
* Generate a test file of the specified size and send it to the specified device
* @param size
* @param sendInterval
* @return
*/
boolean sendFile(String address, int size, Long sendInterval);
/**
* Send files to the last connected device
* @param byteArray
* @param sendInterval
* @return
*/
boolean sendFile(byte[] byteArray, Long sendInterval);
/**
* Send files to specified devices
* @param byteArray
* @param sendInterval
* @return
*/
boolean sendFile(String address, byte[] byteArray, Long sendInterval);
/**
* Send commands to the last connected device
* @param command
*/
void sendATCommand(Set<String> command);
/**
* Send commands to specified devices
* @param address
* @param command
*/
void sendATCommand(String address, Set<String> command);
/**
* Stop sending data to the last connected device
*/
void stopSend();
/**
* Stop sending data to specified devices
* @param address
*/
void stopSend(String address);
API Usage
Search
BLE Search Method
FscBleCentralApi.start();
BLE Search Example
FscBleCentralApi sFscBleCentralApi = FscBleCentralApiImp.getInstance();
sFscBleCentralApi.setCallbacks(new FscBleCentralCallbacksImp(){
@Override
public void blePeripheralFound(FscDevice device, int rssi, byte[] record) {
// Scan to device
}
});
sFscBleCentralApi.startScan();
BLE Stop Search Method
FscBleCentralApi.stopScan();
SPP Search Method
FscSppCentralApi.start();
SPP Search Example
FscSppCentralApi sFscSppCentralApi = FscSppCentralApiImp.getInstance();
sFscSppCentralApi.setCallbacks(new FscSppCentralCallbacksImp(){
@Override
public void sppPeripheralFound(FscDevice sppDevice, int rssi) {
// found devices
}
});
sFscSppCentralApi.startScan();
SPP Stop Search Method
FscSppCentralApi.stopScan();
connect
BLE Connection Method
FscBleCentralApi sFscBleCentralApi = FscBleCentralApiImp.getInstance();
sFscBleCentralApi.setCallbacks(new FscBleCentralCallbacksImp(){
@Override
public void blePeripheralConnected(BluetoothGatt gatt, String address) {
// Connection successful
}
});
sFscBleCentralApi.connect();
SPP Connection Method
FscSppCentralApi sFscSppCentralApi = FscSppCentralApiImp.getInstance();
sFscSppCentralApi.setCallbacks(new FscSppCentralCallbacksImp(){
@Override
public void sppPeripheralConnected(BluetoothDevice device) {
// Connection successful
}
});
sFscSppCentralApi.connect();
Disconnect
BLE Disconnection Method
FscBleCentralApi sFscBleCentralApi = FscBleCentralApiImp.getInstance();
sFscBleCentralApi.setCallbacks(new FscBleCentralCallbacksImp(){
@Override
public void blePeripheralDisconnected(BluetoothGatt gatt, String address) {
// Disconnect
}
});
sFscBleCentralApi.disconnect();
SPP Disconnection Method
FscSppCentralApi sFscSppCentralApi = FscSppCentralApiImp.getInstance();
sFscSppCentralApi.setCallbacks(new FscSppCentralCallbacksImp(){
@Override
public void sppPeripheralDisconnected(String address) {
// Disconnect
}
});
sFscSppCentralApiImp.disconnect();
Callback
BLE Callback Method
/**
* Scan to device
* @param device
* @param rssi
* @param scanRecord
*/
void blePeripheralFound(FscDevice device, int rssi, byte[] scanRecord);
/**
* Send Devices
* @param gatt
* @param address
*/
void blePeripheralConnected(BluetoothGatt gatt, String address);
/**
* Disconnect
* @param gatt
* @param address
*/
void blePeripheralDisconnected(BluetoothGatt gatt, String address);
/**
* Discovery Services
* @param gatt
* @param address
* @param services
*/
void servicesFound(BluetoothGatt gatt, String address, List<BluetoothGattService> services);
/**
* Discovery Services
* @param gatt
* @param address
* @param service
* @param characteristic
*/
void characteristicForService(BluetoothGatt gatt, String address, BluetoothGattService service, BluetoothGattCharacteristic characteristic);
/**
* Read Feature Value Information
* @param address
* @param ch
* @param strValue
* @param hexString
* @param rawValue
*/
void readResponse(String address, BluetoothGattCharacteristic ch, String strValue, String hexString, byte[] rawValue);
/**
* mtu change
* @param mtu
* @param status
*/
void bleMtuChanged(int mtu, int status);
SPP callback method
/**
* Scan to device
* @param sppDevice
*/
void sppPeripheralFound(FscDevice sppDevice, int rssi);
/**
* Connection successful
* @param device
*/
void sppPeripheralConnected(BluetoothDevice device);
/**
* Disconnect
* @param address
*/
void sppPeripheralDisconnected(String address);
/**
* send data
* @param address
* @param strValue
* @param hexString
* @param data
*/
void packetSend(String address, String strValue, String hexString, byte[] data);
Same Callback Method
/**
* Start scanning callback
*/
void startScan();
/**
* Stop scanning
*/
void stopScan();
/**
* Received data
* @param address
* @param strValue
* @param dataHexString
* @param data
*/
void packetReceived(String address, String strValue, String dataHexString, byte[] data);
/**
* send data
* @param address
* @param strValue
* @param data
*/
void packetSend(String address, String strValue, byte[] data);
/**
* Send file progress
* @param address
* @param percentage
* @param data
*/
void sendPacketProgress(String address, int percentage, byte[] data);
/**
* OTA Upgrade Progress
* @param address
* @param percentage
* @param status
*/
void otaProgressUpdate(String address, int percentage, int status);
/**
* AT Command mode communication callback
* @param command
* @param parameter
* @param type
* @param status
*/
void atCommandCallBack(String command, String parameter, int type, int status);
/**
* Triggered at the end of AT command sending
*/
void endATCommand();
/**
* Triggered when starting to send AT command
*/
void startATCommand();
Send Data
BLE Data Sending Method
FscBleCentralApi sFscBleCentralApi = FscBleCentralApiImp.getInstance();
sFscBleCentralApiImp.send("abc");
SPP Data Sending Method
FscSppCentralApi sFscSppCentralApi = FscSppCentralApiImp.getInstance();
sFscSppCentralApiImp.send("abc");
Air upgrade
BLE aerial upgrade method
FscBleCentralApi sFscBleCentralApi = FscBleCentralApiImp.getInstance();
sFscBleCentralApi.setCallbacks(new FscBleCentralCallbacksImp(){
public void otaProgressUpdate(address: String, percentage: Int, status: Int) {
// Upgrade progress
}
});
sFscBleCentralApi.connectToOTAWithFactory(
fscDevice.getAddress(),
dfuByte,
reset
);
SPP Air Upgrade Method
FscSppCentralApi sFscSppCentralApi = FscSppCentralApiImp.getInstance();
sFscSppCentralApi.setCallbacks(new FscSppCentralCallbacksImp(){
public void otaProgressUpdate(address: String, percentage: Int, status: Int) {
// Upgrade progress
}
});
sFscSppCentralApi.connectToOTAWithFactory(
fscDevice.getAddress(),
dfuByte,
reset
);