FeasyBeacon SDK For Andorid
FeasyBeacon SDK Android Integration Documentation
[Download FeasyBeacon_SDK_3.3.6]
Version |
Writing date |
Author |
---|---|---|
V3.3.6 |
2024年11月19日 |
Changjigang |
SDK Function Overview
Integrating this SDK into Android applications can quickly achieve the following functions:
Scanning and stopping scanning of Beacon modules
Connection and disconnection of Beacon modules
Beacon module information query and parameter modification
Beacon module aerial upgrade
Understanding instance objects
The BluetoothDeviceWrapper class encapsulates information about Bluetooth devices, used to represent scanned Bluetooth devices
// The BluetoothDeviceWrapper class encapsulates information about Bluetooth devices, used to represent scanned Bluetooth devices.
public class BluetoothDeviceWrapper implements Serializable {
// Beacon type constant
public static final int EDDYSTONE_TYPE = 0x16;
public static final int ALTBEACON_TYPE = 0xFF;
public static final int COMPLETE_LOCAL_NAME = 0x09;
private String address; // Bluetooth Device Address
private String name; // Bluetooth device name
private Integer rssi; // signal intensity
private long timestampNanos = 0; // time stamp
// Beacon object
private IBeacon iBeacon = null;
private EddystoneBeacon eddystoneBeacon = null;
private AltBeacon altBeacon = null;
private FeasyBeacon feasyBeacon = null;
private String completeLocalName = null; // Full local name
// gSensor object
private Monitor monitor = null;
public BluetoothDeviceWrapper(String address) {
this.address = address;
}
public BluetoothDeviceWrapper(String address, String name, int rssi) {
this.address = address;
this.name = name;
this.rssi = rssi;
}
public BluetoothDeviceWrapper(String address, String name, int rssi, long timestampNanos) {
this.address = address;
this.name = name;
this.rssi = rssi;
this.timestampNanos = timestampNanos;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getRssi() {
return rssi;
}
public void setRssi(Integer rssi) {
this.rssi = rssi;
}
public long getTimestampNanos() {
return timestampNanos;
}
public void setTimestampNanos(long timestampNanos) {
this.timestampNanos = timestampNanos;
}
public IBeacon getIBeacon() {
return iBeacon;
}
public void setIBeacon(IBeacon iBeacon) {
if (iBeacon != null) {
this.iBeacon = iBeacon;
this.eddystoneBeacon = null;
this.altBeacon = null;
}
}
public EddystoneBeacon getEddystoneBeacon() {
return eddystoneBeacon;
}
public void setEddystoneBeacon(EddystoneBeacon eddystoneBeacon) {
if (eddystoneBeacon != null) {
this.eddystoneBeacon = eddystoneBeacon;
this.iBeacon = null;
this.altBeacon = null;
}
}
public AltBeacon getAltBeacon() {
return altBeacon;
}
public void setAltBeacon(AltBeacon altBeacon) {
if (altBeacon != null) {
this.altBeacon = altBeacon;
this.iBeacon = null;
this.eddystoneBeacon = null;
}
}
public FeasyBeacon getFeasyBeacon() {
return feasyBeacon;
}
public void setFeasyBeacon(FeasyBeacon feasyBeacon) {
this.feasyBeacon = feasyBeacon;
}
public String getCompleteLocalName() {
return completeLocalName;
}
public void setCompleteLocalName(String completeLocalName) {
this.completeLocalName = completeLocalName;
}
public Monitor getMonitor() {
return monitor;
}
public void setMonitor(Monitor monitor) {
this.monitor = monitor;
}
}
The EddystoneBeacon class represents the Beacon of the Eddystone protocol
// The EddystoneBeacon class represents the Beacon of the Eddystone protocol
public class EddystoneBeacon extends FeasyBeacon {
private final String TAG = "FscEddystone";
private String frameTypeString; // Eddystone type(URL、UID、TLM)
private String frameTypeHex; // Hexadecimal representation of Eddystone type
private int eddystoneRssiOrVersion; // Eddystone's transmission power or version number
private String dataValue; // Eddystone's broadcast data
private String url;
private String nameSpace;
private String instance;
private String reserved;
private String batteryVoltage;
private String temperature;
private String advertisementsCount;
private String timeSincePowerUp;
public int getEddystoneRssiOrVersion() {
return eddystoneRssiOrVersion;
}
public void setEddystoneRssiOrVersion(int eddystoneRssiOrVersion) {
this.eddystoneRssiOrVersion = eddystoneRssiOrVersion;
}
public String getFrameTypeString() {
return frameTypeString;
}
public void setFrameTypeString(String frameTypeString) {
this.frameTypeString = frameTypeString;
}
public String getFrameTypeHex() {
return frameTypeHex;
}
public void setFrameTypeHex(String frameTypeHex) {
if (frameTypeHex.length() == 1) {
frameTypeHex = "0" + frameTypeHex;
}
this.frameTypeHex = frameTypeHex;
}
public String getDataValue() {
return dataValue;
}
public void setDataValue(String dataValue) {
this.dataValue = dataValue;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getNameSpace() {
return nameSpace;
}
public void setNameSpace(String nameSpace) {
this.nameSpace = nameSpace;
}
public String getInstance() {
return instance;
}
public void setInstance(String instance) {
this.instance = instance;
}
public String getReserved() {
return reserved;
}
public void setReserved(String reserved) {
this.reserved = reserved;
}
public String getBatteryVoltage() {
return batteryVoltage;
}
public void setBatteryVoltage(String batteryVoltage) {
this.batteryVoltage = batteryVoltage;
}
public String getTemperature() {
return temperature;
}
public void setTemperature(String temperature) {
this.temperature = temperature;
}
public String getAdvertisementsCount() {
return advertisementsCount;
}
public void setAdvertisementsCount(String advertisementsCount) {
this.advertisementsCount = advertisementsCount;
}
public String getTimeSincePowerUp() {
return timeSincePowerUp;
}
public void setTimeSincePowerUp(String timeSincePowerUp) {
this.timeSincePowerUp = timeSincePowerUp;
}
}
AltBeacon represents a Bluetooth beacon of AltBeacon type
// The AltBeacon class represents Bluetooth beacons of AltBeacon type
public class AltBeacon extends FeasyBeacon {
private String reservedId; // Reserve ID
private String manufacturerId; // Manufacturer ID
private String beaconId; // Beacon ID
private int altBeaconRssi; // RSSI value of AltBeacon
private String feature; // feature
public int getAltBeaconRssi() {
return altBeaconRssi;
}
public void setAltBeaconRssi(int altBeaconRssi) {
this.altBeaconRssi = altBeaconRssi;
}
public String getBeaconId() {
return beaconId;
}
public void setBeaconId(String beaconId) {
this.beaconId = beaconId;
}
public String getManufacturerId() {
return manufacturerId;
}
public void setManufacturerId(String manufacturerId) {
this.manufacturerId = manufacturerId;
}
public String getReservedId() {
return reservedId;
}
public void setReservedId(String reservedId) {
this.reservedId = reservedId;
}
public String getFeature() {
return feature;
}
public void setFeature(String feature) {
this.feature = feature;
}
}
The IBecon class represents beacon devices for the iBeacon protocol
// The IBecon class represents beacon devices for the iBeacon protocol
public class IBeacon extends FeasyBeacon {
private String company; // Company identification
private String type; // Beacon type
private String dataLength; // Data length
private int major; // Major value, used to distinguish beacons
private int minor; // Minor value, used to distinguish beacons
private String uuid; // UUID, used to uniquely identify beacons
private int rssi; // Received Signal Strength Indication (RSSI)
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDataLength() {
return dataLength;
}
public void setDataLength(String dataLength) {
this.dataLength = dataLength;
}
public int getMajor() {
return major;
}
public void setMajor(int major) {
this.major = major;
}
public int getMinor() {
return minor;
}
public void setMinor(int minor) {
this.minor = minor;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public int getRssi() {
return rssi;
}
public void setRssi(int rssi) {
this.rssi = rssi;
}
}
The Monitor class represents a type of monitor device, including its temperature, humidity, battery level, and name attributes
// The Monitor class represents a type of monitor device, including its temperature, humidity, battery level, and name attributes
public class Monitor extends FeasyBeacon {
private String temperature; // Temperature value
private String humidity; // Humidity value
private int battery; // battery level
private String name; // Monitor Name
public String getTemperature() {
return temperature;
}
public void setTemperature(String temperature) {
this.temperature = temperature;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
@Override
public int getBattery() {
return battery;
}
@Override
public void setBattery(int battery) {
this.battery = battery;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The BeaconBean class is used to represent the attribute information of Bluetooth beacons (including iBeacon, eddystone_URL, eddystone_uid, altBeacon)
// The BeaconBean class is used to represent the attribute information of Bluetooth beacons
public class BeaconBean implements Serializable {
private String index; // index
private String beaconType; // Beacon type (iBeacon, Eddystone_URL, Eddystone_uid)
//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
private String instance; // An instance of Eddystone_uid
private String reserved; // EddyStoner's reserved fields
//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 fields
private String power; // Beacon TX power
private boolean connectable; // Can it be connected
private boolean enable; // Is broadcasting enabled
private String version;// Firmware version
private int interval = 1000; // Beacon interval, default value is 1000ms
private String parentName; // Parent node name
private String txpower = "2"; // Beacon TX power, default value of 2
private String phy = "0"; // Physical layer, default value is 0
public BeaconBean() {
}
public BeaconBean(String index, String beaconType) {
this.index = index;
this.beaconType = beaconType;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getBeaconType() {
return beaconType;
}
public void setBeaconType(String beaconType) {
this.beaconType = beaconType;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getMinor() {
return minor;
}
public void setMinor(String minor) {
this.minor = minor;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getNameSpace() {
return nameSpace;
}
public void setNameSpace(String nameSpace) {
this.nameSpace = nameSpace;
}
public String getInstance() {
return instance;
}
public void setInstance(String instance) {
this.instance = instance;
}
public String getReserved() {
return reserved;
}
public void setReserved(String reserved) {
this.reserved = reserved;
}
public String getId1() {
return id1;
}
public void setId1(String id1) {
this.id1 = id1;
}
public String getId2() {
return id2;
}
public void setId2(String id2) {
this.id2 = id2;
}
public String getId3() {
return id3;
}
public void setId3(String id3) {
this.id3 = id3;
}
public String getManufacturerId() {
return manufacturerId;
}
public void setManufacturerId(String manufacturerId) {
this.manufacturerId = manufacturerId;
}
public String getManufacturerReserved() {
return manufacturerReserved;
}
public void setManufacturerReserved(String manufacturerReserved) {
this.manufacturerReserved = manufacturerReserved;
}
public String getPower() {
return power;
}
public void setPower(String power) {
this.power = power;
}
public boolean isConnectable() {
return connectable;
}
public void setConnectable(boolean connectable) {
this.connectable = connectable;
}
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public int getInterval() {
return interval;
}
public void setInterval(int interval) {
this.interval = interval;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
public String getTxpower() {
return txpower;
}
public void setTxpower(String txpower) {
this.txpower = txpower;
}
public String getPhy() {
return phy;
}
public void setPhy(String phy) {
this.phy = phy;
}
}
Quick Integration (Android)
Integrated SDK
If you have not yet installed Android Studio, please visit [Android official website]
Create Android project
Create a new project in Android Studio.
Place the featybecon.jar and so libraries in the project libs directory

Configure the build.gradle file
dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
}
Configure the AndroidManifest.xml file
In your application, permission needs to be granted in the AndroidManifest.xml file. Please add the following code to your application manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.feasycom.feasybeacon">
<!-- Bluetooth permissions -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Location permissions -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FeasyBeacon1">
<!-- service -->
<service android:name="com.feasycom.service.AtCommandService" android:enabled="true" android:exported="false" />
<service android:name="com.feasycom.service.OTABLEService" android:enabled="true" android:exported="false" />
</application>
</manifest>
Example of interface usage method
SUOTA SDK Upgrade Usage Example
class SuotaActivity : BaseActivity<ActivitySuotaBinding>(),
DeviceInfoFragment.OnDeviceInfoFragmentInteractionListener,
AvailableFirmwareFragment.OnAvailableFirmwareFragmentInteractionListener,
UpdateFirmwareFragment.OnUpdateFirmwareFragmentInteractionListener,
BaseSuotaFragment.OnBaseSuotaFragmentInteractionListener{
private lateinit var suotaFile: SuotaFile
private lateinit var suotaManager: SuotaManager
//Establish GATT connection
override fun connect() {
//Initialize SuotaManager
suotaManager = SuotaManager(lifecycle, this, bluetoothDevice, SuotaCallback(this)).apply {
setUiContext(this@SuotaActivity)
connect()
}
}
//Set upgrade file
override fun onFirmwareSelected(suotaFile: SuotaFile?) {
suotaManager.suotaFile = suotaFile
suotaManager.initializeSuota(240, 3, 0, 1, 4, 2)
}
//Start firmware upgrade
override fun startSuotaProtocol() {
suotaManager.startUpdate()
}
}
//A callback class used to handle SUOTA (wireless firmware upgrade) events.
class SuotaCallback(@NonNull private val suotaActivityRef: SuotaActivity): SuotaManagerCallback() {
// Called when the connection status changes.
override fun onConnectionStateChange(newStatus: SuotaProfile.SuotaManagerStatus) {
}
// When a service is discovered, it is called.
override fun onServiceDiscovered() {
}
// Called when reading feature values.
override fun onCharacteristicRead(characteristicGroup: SuotaProfile.CharacteristicGroup, characteristic: BluetoothGattCharacteristic) {
}
// Called when reading device information is complete.
override fun onDeviceInfoReadCompleted(status: SuotaProfile.DeviceInfoReadStatus) {
}
// Called when the device is ready for SUOTA.
override fun onDeviceReady() {
}
// Record SUOTA status and additional information.
override fun onSuotaLog(state: SuotaProfile.SuotaProtocolState, type: ISuotaManagerCallback.SuotaLogType, log: String) {
}
// Called during block data transmission.
override fun onChunkSend(chunkCount: Int, totalChunks: Int, chunk: Int, block: Int, blockChunks: Int, totalBlocks: Int) {
}
// Update the progress bar when there is a change in upload progress.
override fun onUploadProgress(percent: Float) {
}
// Called when the SUOTA process is successfully completed.
override fun onSuccess(totalElapsedSeconds: Double, imageUploadElapsedSeconds: Double) {
}
// Called when SUOTA process fails.
override fun onFailure(errorCode: Int) {
}
// Called when sending a restart command.
override fun onRebootSent() {
}
// Update speed statistics during the upload process.
override fun updateSpeedStatistics(current: Double, max: Double, min: Double, avg: Double) {
}
// Update the current speed during the upload process.
override fun updateCurrentSpeed(currentSpeed: Double) {
}
// Process the display of a suspended restart dialog box.
override fun pendingRebootDialog(rebootDialog: SupportCustomDialogFragment) {
}
}