Feasycom FeasyBeacon SDK Android User Guide3.3.6
Feasycom FeasyBeacon SDK Android User Guide3.3.6
Lt
FeasyBeacon SDK Android User
.,
Co
Guide 3.3.6
om
yc
as
Fe
n
he
z
en
Sh
1
Table of contents
d .
1.1 SDK Function Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Lt
1.1.1 Integrating this SDK into Android applications can quickly achieve
the following functions: . . . . . . . . . . . . . . . . . . . . . . . . . 1
.,
1.2 Understanding instance objects . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Co
1.2.1 The BluetoothDeviceWrapper class encapsulates information about
Bluetooth devices, used to represent scanned Bluetooth devices . . . . 2
om
1.2.2 The EddystoneBeacon class represents the Beacon of the Eddystone
protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
yc
1.2.5 The Monitor class represents a type of monitor device, including its
Fe
tone_uid, altBeacon) . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.3 Quick Integration (Android) . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Sh
i
Chapter 1
.d
Documentation
Lt
.,
Co
[Download FeasyBeacon_SDK_3.3.6]
om
Version Writing date Author
V3.3.6 2024 年 11 月 19 日 Changji-
yc
gang
as
Fe
1.1.1 Integrating this SDK into Android applications can quickly achieve
z
1
FeasyBeacon SDK Android User Guide 3.3.6
d .
public static final int COMPLETE_LOCAL_NAME = 0x09;
Lt
private String address; // Bluetooth Device Address
.,
private String name; // Bluetooth device name
Co
private Integer rssi; // signal intensity
private long timestampNanos = 0; // time stamp
om
// Beacon object
private IBeacon iBeacon = null;
yc
// gSensor object
z
this.address = address;
}
d .
public String getAddress() {
Lt
return address;
}
.,
Co
public void setAddress(String address) {
this.address = address;
}
om
public String getName() {
yc
return name;
}
as
Fe
}
he
return rssi;
}
Sh
d .
this.iBeacon = iBeacon;
Lt
this.eddystoneBeacon = null;
this.altBeacon = null;
.,
}
Co
}
if (eddystoneBeacon != null) {
Fe
this.eddystoneBeacon = eddystoneBeacon;
this.iBeacon = null;
n
this.altBeacon = null;
he
}
}
z
en
return altBeacon;
}
d .
public String getCompleteLocalName() {
Lt
return completeLocalName;
}
.,
Co
public void setCompleteLocalName(String completeLocalName) {
this.completeLocalName = completeLocalName;
}
om
public Monitor getMonitor() {
yc
return monitor;
}
as
Fe
}
he
}
z
en
tone protocol
d .
Lt
private String batteryVoltage;
private String temperature;
.,
private String advertisementsCount;
Co
private String timeSincePowerUp;
,→ {
Fe
this.eddystoneRssiOrVersion = eddystoneRssiOrVersion;
}
n
he
}
Sh
d .
public void setDataValue(String dataValue) {
Lt
this.dataValue = dataValue;
}
.,
Co
public String getUrl() {
return url;
}
om
public void setUrl(String url) {
yc
this.url = url;
}
as
Fe
}
he
this.nameSpace = nameSpace;
}
Sh
d .
}
Lt
public void setBatteryVoltage(String batteryVoltage) {
.,
this.batteryVoltage = batteryVoltage;
Co
}
this.temperature = temperature;
Fe
}
n
return advertisementsCount;
}
z
en
this.advertisementsCount = advertisementsCount;
}
d .
private String reservedId; // Reserve ID
Lt
private String manufacturerId; // Manufacturer ID
private String beaconId; // Beacon ID
.,
private int altBeaconRssi; // RSSI value of AltBeacon
Co
private String feature; // feature
om
public int getAltBeaconRssi() {
return altBeaconRssi;
}
yc
as
}
n
return beaconId;
z
}
en
this.beaconId = beaconId;
}
d .
Lt
public String getFeature() {
return feature;
.,
}
Co
public void setFeature(String feature) {
this.feature = feature;
om
}
}
yc
as
1.2.4 The IBecon class represents beacon devices for the iBeacon proto-
Fe
col
n
he
d .
Lt
public void setType(String type) {
this.type = type;
.,
}
Co
public String getDataLength() {
return dataLength;
om
}
yc
}
Fe
return major;
he
}
z
en
d .
return rssi;
Lt
}
.,
public void setRssi(int rssi) {
Co
this.rssi = rssi;
}
}
om
yc
d .
@Override
Lt
public int getBattery() {
return battery;
.,
}
Co
@Override
public void setBattery(int battery) {
om
this.battery = battery;
}
yc
return name;
Fe
}
n
this.name = name;
}
z
en
}
Sh
1.2.6 The FeasyBeacon class represents a beacon device, including its re-
lated properties and configuration information
d .
Lt
private boolean keyConfig; // grouping key
private boolean gSensor; // Configure sensors
.,
private boolean buzzer; // Configure buzzer
Co
private boolean led; // Configure LED
private boolean nfc; // Configure NFC
private boolean longRange; // Configure Long Distance
om
private boolean connectable; // Can it be connected
private String module; // Module type
yc
}
Sh
d .
Lt
public String getDeviceName() {
return deviceName;
.,
}
Co
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
om
}
yc
}
Fe
this.deviceAddress = deviceAddress;
he
}
z
en
d .
this.keyConfig = keyConfig;
Lt
}
.,
public boolean getGSensor() {
Co
return gSensor;
}
om
public void setGSensor(boolean gSensor) {
this.gSensor = gSensor;
yc
}
as
return buzzer;
}
n
he
}
Sh
d .
Lt
public void setLongRange(boolean longRange) {
this.longRange = longRange;
.,
}
Co
} om
1.2.7 The BeaconBean class is used to represent the attribute informa-
tion of Bluetooth beacons (including iBeacon, eddystone_URL, ed-
yc
dystone_uid, altBeacon)
as
Fe
,→ Eddystone_uid)
Sh
//iBeacon
private String uuid; // IBeacon's UUID
private String major; // The Major value of iBeacon
private String minor;// Minor value of iBeacon
//eddystone_url
private String url; // The URL of Eddystone_URL
//eddystone_uid
private String nameSpace; // The namespace of Eddystone_uid
(continues on next page)
//altBeacon
private String id1; // ID1 of AltBeacon
private String id2; // ID2 of AltBeacon
private String id3; // ID3 of AltBeacon
private String manufacturerId; // Manufacturer ID
private String manufacturerReserved; // Manufacturer reserved␣
d .
,→ fields
Lt
private String power; // Beacon TX power
.,
private boolean connectable; // Can it be connected
Co
private boolean enable; // Is broadcasting enabled
private String version;// Firmware version
private int interval = 1000; // Beacon interval, default value is␣
om
,→ 1000ms
private String parentName; // Parent node name
yc
,→
public BeaconBean() {
n
}
he
this.index = index;
this.beaconType = beaconType;
Sh
d .
return uuid;
Lt
}
.,
public void setUuid(String uuid) {
Co
this.uuid = uuid;
}
om
public String getMajor() {
return major;
yc
}
as
this.major = major;
}
n
he
}
Sh
d .
Lt
public String getInstance() {
return instance;
.,
}
Co
public void setInstance(String instance) {
this.instance = instance;
om
}
yc
}
Fe
this.reserved = reserved;
he
}
z
en
d .
this.id3 = id3;
Lt
}
.,
public String getManufacturerId() {
Co
return manufacturerId;
}
om
public void setManufacturerId(String manufacturerId) {
this.manufacturerId = manufacturerId;
yc
}
as
return manufacturerReserved;
}
n
he
}
Sh
d .
Lt
public void setEnable(boolean enable) {
this.enable = enable;
.,
}
Co
public String getVersion() {
return version;
om
}
yc
}
Fe
return interval;
he
}
z
en
d .
return phy;
Lt
}
.,
public void setPhy(String phy) {
Co
this.phy = phy;
}
}
om
yc
• If you have not yet installed Android Studio, please visit [Android official website]
z he
1.3.3 Place the featybecon.jar and so libraries in the project libs direc-
tory
d .
Lt
.,
Co
om
1.3.4 Configure the build.gradle file
yc
dependencies {
as
}
n
he
<application
d .
android:name=".App"
Lt
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
.,
android:label="@string/app_name"
Co
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FeasyBeacon1">
om
<!-- service -->
yc
<service android:name="com.feasycom.service.AtCommandService"␣
android:enabled="true" android:exported="false" />
as
,→
<service android:name="com.feasycom.service.OTABLEService"␣
Fe
</application>
he
</manifest>
z
en
Sh
object BluetoothRepository {
d .
// Instruction Bean
Lt
val commandBean: CommandBean = CommandBean()
// FscBeacon Central API instance
.,
private val mFscBeaconCentralApi by lazy {
Co
FscBeaconApiImp.getInstance(App.sContext).apply {
initialize()
setCallbacks(BeaconCallbacks())
om
}
}
yc
/**
as
*/
fun isBluetoothEnabled() = mFscBeaconCentralApi.isBluetoothEnabled
n
he
/**
* Start scanning Bluetooth devices
z
en
*/
fun startScan() = mFscBeaconCentralApi.startScan()
Sh
/**
* Start scanning at the specified time
* @param scanTime
*/
fun startScanTime(scanTime: Int) = mFscBeaconCentralApi.
,→ startScan(scanTime)
/**
* Stop scanning
(continues on next page)
/**
* Determine if the device is connected
*/
fun isConnect() = mFscBeaconCentralApi.isConnected
/**
d .
* Connect to specified devices
Lt
* @param device
* @param pin
.,
*/
Co
fun connect(device: BluetoothDeviceWrapper, pin: String) =␣
,→ mFscBeaconCentralApi.connect(device, pin)
om
/**
* Disconnect
yc
*/
fun disconnect() = mFscBeaconCentralApi.disconnect()
as
Fe
/**
* Determine if Beacon information is complete
n
*/
he
/**
* Add Beacon information
Sh
* @param beaconBean
*/
fun addBeaconInfo(beaconBean: BeaconBean) = mFscBeaconCentralApi.
,→ addBeaconInfo(beaconBean)
/**
* Delete Beacon information
* @param beaconBean
*/
fun deleteBeaconInfo(beaconBean: BeaconBean) {
(continues on next page)
/**
* Set device name
* @param deviceName
*/
fun setDeviceName(deviceName: String) = mFscBeaconCentralApi.
d .
,→ setDeviceName(deviceName)
Lt
/**
.,
* Set device PIN code
Co
* @param pin
*/
fun setDevicePin(pin: String) = mFscBeaconCentralApi.
om
,→ setDevicePin(pin)
yc
/**
* Set broadcast interval
as
* @param intervalTime
Fe
*/
fun setBroadcastInterval(intervalTime: String) =␣
n
,→ mFscBeaconCentralApi.setBroadcastInterval(intervalTime)
he
/**
z
en
* Restore device
*/
Sh
/**
* Query or set firmware key
*/
fun setFirmwareKey(command : String) = mFscBeaconCentralApi.
,→ setFirmwareKey(command)
/**
* Set application key
(continues on next page)
/**
* Get Beacon broadcast parameters
*/
fun beaconBroadcastParameters() = mFscBeaconCentralApi.
,→ beaconBroadcastParameters();
d .
/**
Lt
* Set TLM status
* @param isTlm
.,
*/
Co
fun setTlm(isTlm: Boolean) = mFscBeaconCentralApi.setTlm(isTlm)
/**
om
* Set broadcast extension
* @param isBroadcastExtensions
yc
*/
fun setBroadcastExtensions(isBroadcastExtensions: Boolean) =␣
as
,→ mFscBeaconCentralApi.setBroadcastExtensions(isBroadcastExtensions)
Fe
/**
n
* @param dfuFile
*/
z
en
/**
* Starting OTA update
* @param dfuFile
* @param reset
*/
fun startOtaUpdate(dfuFile: ByteArray, reset: Boolean) =␣
,→ mFscBeaconCentralApi.startOtaUpdate(dfuFile, reset)
/**
(continues on next page)
/**
* Batch setting Beacon information
*/
fun setBatchBeaconInfo() = mFscBeaconCentralApi.
,→ saveBatch(commandBean)
d .
Lt
/**
* Register View Callback
.,
* @param callback
Co
*/
fun registerViewCallback(callback: FscBleCallback) {
if (mCallbacks.contains(callback)) return
om
try {
mCallbacks.add(callback)
yc
}
Fe
}
n
/**
he
*/
fun unRegisterViewCallback(callback: FscBleCallback) {
Sh
try {
mCallbacks.remove(callback)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* Get device information
* @param feasyBeacon
(continues on next page)
/**
* Internal callback class, used to handle callback events for␣
,→ Bluetooth operations
d .
*/
Lt
class BeaconCallbacks : FscBeaconCallbacks {
.,
// Start scanning
Co
override fun startScan() {}
// Stop scanning
om
override fun stopScan() {}
yc
,→ status: Int) {
Fe
mCallbacks.forEach { it.onConnectProgressUpdate(status) }
}
n
he
try {
// Check if the device is iBeacon, EddystoneBeacon,␣
,→ or AltBeacon
if (device.iBeacon != null || device.eddystoneBeacon !
,→ = null || device.altBeacon != null) {
notifyCallbacks { it.onBeacon(device) }
}
d .
} catch (e: Exception) {
Lt
e.printStackTrace()
}
.,
}
Co
// Notify all callback functions
private inline fun notifyCallbacks(action: (FscBleCallback) ->
om
,→ Unit) {
mCallbacks.forEach { callback ->
yc
try {
action(callback)
as
e.printStackTrace()
}
n
}
he
}
z
en
,→ device: BluetoothDevice?) {
mCallbacks.forEach { it.onConnectedSuccess() }
}
// Discovery Services
override fun servicesFound(
d .
gatt: BluetoothGatt?,
Lt
device: BluetoothDevice?,
services: ArrayList<BluetoothGattService>?
.,
) {}
Co
// Discovering features in services
override fun characteristicForService(
om
gatt: BluetoothGatt?,
device: BluetoothDevice?,
yc
service: BluetoothGattService?,
characteristic: BluetoothGattCharacteristic?
as
) {}
Fe
// Received packet
n
gatt: BluetoothGatt?,
device: BluetoothDevice?,
z
en
service: BluetoothGattService?,
ch: BluetoothGattCharacteristic?,
Sh
strValue: String,
hexString: String,
rawValue: ByteArray,
timestamp: String?
) {
mCallbacks.forEach { it.onPacketReceived(strValue,␣
,→ hexString, rawValue) }
}
d .
) {}
Lt
// Send packet progress
.,
override fun sendPacketProgress(
Co
gatt: BluetoothGatt?,
device: BluetoothDevice?,
ch: BluetoothGattCharacteristic?,
om
percentage: Int,
sendByte: ByteArray?
yc
) {}
as
}
he
mCallbacks.forEach { it.onDeviceInfo(parameterName,␣
,→ parameter) }
}
}
}
d .
private lateinit var suotaManager: SuotaManager
Lt
//Establish GATT connection
.,
override fun connect() {
Co
//Initialize SuotaManager
suotaManager = SuotaManager(lifecycle, this,␣
bluetoothDevice, SuotaCallback(this)).apply {
om
,→
setUiContext(this@SuotaActivity)
connect()
yc
}
as
}
Fe
suotaManager.suotaFile = suotaFile
he
suotaManager.initializeSuota(240, 3, 0, 1, 4, 2)
}
z
en
d .
Lt
}
.,
// Called when reading feature values.
Co
override fun onCharacteristicRead(characteristicGroup:␣
,→ SuotaProfile.CharacteristicGroup, characteristic:␣
,→ BluetoothGattCharacteristic) {
om
}
yc
,→ DeviceInfoReadStatus) {
n
}
he
d .
Lt
// Called when the SUOTA process is successfully completed.
override fun onSuccess(totalElapsedSeconds: Double,␣
.,
,→ imageUploadElapsedSeconds: Double) {
Co
}
om
// Called when SUOTA process fails.
override fun onFailure(errorCode: Int) {
yc
}
as
Fe
}
z
en
d .
Lt
.,
Co
om
yc
as
Fe
n
z he
en
Sh