0% found this document useful (0 votes)
76 views40 pages

Feasycom FeasyBeacon SDK Android User Guide3.3.6

Uploaded by

amiel.arik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views40 pages

Feasycom FeasyBeacon SDK Android User Guide3.3.6

Uploaded by

amiel.arik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

d .

Lt
FeasyBeacon SDK Android User

.,
Co
Guide 3.3.6
om
yc
as
Fe
n
he
z
en
Sh

1
Table of contents

1 FeasyBeacon SDK Android Integration Documentation 1

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.3 AltBeacon represents a Bluetooth beacon of AltBeacon type . . . . . . 9


1.2.4 The IBecon class represents beacon devices for the iBeacon protocol . . 10
as

1.2.5 The Monitor class represents a type of monitor device, including its
Fe

temperature, humidity, battery level, and name attributes . . . . . . . . 12


1.2.6 The FeasyBeacon class represents a beacon device, including its re-
n

lated properties and configuration information . . . . . . . . . . . . . 13


he

1.2.7 The BeaconBean class is used to represent the attribute information


of Bluetooth beacons (including iBeacon, eddystone_URL, eddys-
z
en

tone_uid, altBeacon) . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.3 Quick Integration (Android) . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Sh

1.3.1 Integrated SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23


1.3.2 Create Android project . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.3.3 Place the featybecon.jar and so libraries in the project libs directory . . 24
1.3.4 Configure the build.gradle file . . . . . . . . . . . . . . . . . . . . . . 24
1.3.5 Configure the AndroidManifest.xml file . . . . . . . . . . . . . . . . . 24
1.4 Example of interface usage method . . . . . . . . . . . . . . . . . . . . . . . . 25
1.4.1 Responsible for managing Bluetooth operations and related data . . . . 25
1.4.2 SUOTA SDK Upgrade Usage Example . . . . . . . . . . . . . . . . . 35

i
Chapter 1

FeasyBeacon SDK Android Integration

.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 SDK Function Overview


n
he

1.1.1 Integrating this SDK into Android applications can quickly achieve
z

the following functions:


en

• Scanning and stopping scanning of Beacon modules


Sh

• Connection and disconnection of Beacon modules

• Beacon module information query and parameter modification

• Beacon module aerial upgrade

1.2 Understanding instance objects

1
FeasyBeacon SDK Android User Guide 3.3.6

1.2.1 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;

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

private EddystoneBeacon eddystoneBeacon = null;


as

private AltBeacon altBeacon = null;


private FeasyBeacon feasyBeacon = null;
Fe

private String completeLocalName = null; // Full local name


n
he

// gSensor object
z

private Monitor monitor = null;


en

public BluetoothDeviceWrapper(String address) {


Sh

this.address = address;
}

public BluetoothDeviceWrapper(String address, String name, int␣


,→ rssi) {
this.address = address;
this.name = name;
this.rssi = rssi;
}
(continues on next page)

1.2. Understanding instance objects 2


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)

public BluetoothDeviceWrapper(String address, String name, int␣


,→ rssi, long timestampNanos) {
this.address = address;
this.name = name;
this.rssi = rssi;
this.timestampNanos = timestampNanos;
}

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

public void setName(String name) {


this.name = name;
n

}
he

public Integer getRssi() {


z
en

return rssi;
}
Sh

public void setRssi(Integer rssi) {


this.rssi = rssi;
}

public long getTimestampNanos() {


return timestampNanos;
}

public void setTimestampNanos(long timestampNanos) {


(continues on next page)

1.2. Understanding instance objects 3


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


this.timestampNanos = timestampNanos;
}

public IBeacon getIBeacon() {


return iBeacon;
}

public void setIBeacon(IBeacon iBeacon) {


if (iBeacon != null) {

d .
this.iBeacon = iBeacon;

Lt
this.eddystoneBeacon = null;
this.altBeacon = null;

.,
}

Co
}

public EddystoneBeacon getEddystoneBeacon() {


om
return eddystoneBeacon;
}
yc

public void setEddystoneBeacon(EddystoneBeacon eddystoneBeacon) {


as

if (eddystoneBeacon != null) {
Fe

this.eddystoneBeacon = eddystoneBeacon;
this.iBeacon = null;
n

this.altBeacon = null;
he

}
}
z
en

public AltBeacon getAltBeacon() {


Sh

return altBeacon;
}

public void setAltBeacon(AltBeacon altBeacon) {


if (altBeacon != null) {
this.altBeacon = altBeacon;
this.iBeacon = null;
this.eddystoneBeacon = null;
}
}
(continues on next page)

1.2. Understanding instance objects 4


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)

public FeasyBeacon getFeasyBeacon() {


return feasyBeacon;
}

public void setFeasyBeacon(FeasyBeacon feasyBeacon) {


this.feasyBeacon = feasyBeacon;
}

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

public void setMonitor(Monitor monitor) {


this.monitor = monitor;
n

}
he

}
z
en

1.2.2 The EddystoneBeacon class represents the Beacon of the Eddys-


Sh

tone 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␣
(continues on next page)

1.2. Understanding instance objects 5


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


,→ 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;

d .
Lt
private String batteryVoltage;
private String temperature;

.,
private String advertisementsCount;

Co
private String timeSincePowerUp;

public int getEddystoneRssiOrVersion() {


om
return eddystoneRssiOrVersion;
}
yc

public void setEddystoneRssiOrVersion(int eddystoneRssiOrVersion)


as

,→ {
Fe

this.eddystoneRssiOrVersion = eddystoneRssiOrVersion;
}
n
he

public String getFrameTypeString() {


return frameTypeString;
z
en

}
Sh

public void setFrameTypeString(String frameTypeString) {


this.frameTypeString = frameTypeString;
}

public String getFrameTypeHex() {


return frameTypeHex;
}

public void setFrameTypeHex(String frameTypeHex) {


if (frameTypeHex.length() == 1) {
(continues on next page)

1.2. Understanding instance objects 6


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


frameTypeHex = "0" + frameTypeHex;
}
this.frameTypeHex = frameTypeHex;
}

public String getDataValue() {


return dataValue;
}

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

public String getNameSpace() {


return nameSpace;
n

}
he

public void setNameSpace(String nameSpace) {


z
en

this.nameSpace = nameSpace;
}
Sh

public String getInstance() {


return instance;
}

public void setInstance(String instance) {


this.instance = instance;
}

public String getReserved() {


(continues on next page)

1.2. Understanding instance objects 7


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


return reserved;
}

public void setReserved(String reserved) {


this.reserved = reserved;
}

public String getBatteryVoltage() {


return batteryVoltage;

d .
}

Lt
public void setBatteryVoltage(String batteryVoltage) {

.,
this.batteryVoltage = batteryVoltage;

Co
}

public String getTemperature() {


om
return temperature;
}
yc

public void setTemperature(String temperature) {


as

this.temperature = temperature;
Fe

}
n

public String getAdvertisementsCount() {


he

return advertisementsCount;
}
z
en

public void setAdvertisementsCount(String advertisementsCount) {


Sh

this.advertisementsCount = advertisementsCount;
}

public String getTimeSincePowerUp() {


return timeSincePowerUp;
}

public void setTimeSincePowerUp(String timeSincePowerUp) {


this.timeSincePowerUp = timeSincePowerUp;
}
(continues on next page)

1.2. Understanding instance objects 8


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

1.2.3 AltBeacon represents a Bluetooth beacon of AltBeacon type

// The AltBeacon class represents Bluetooth beacons of AltBeacon␣


,→ type
public class AltBeacon extends FeasyBeacon {

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

public void setAltBeaconRssi(int altBeaconRssi) {


this.altBeaconRssi = altBeaconRssi;
Fe

}
n

public String getBeaconId() {


he

return beaconId;
z

}
en

public void setBeaconId(String beaconId) {


Sh

this.beaconId = beaconId;
}

public String getManufacturerId() {


return manufacturerId;
}

public void setManufacturerId(String manufacturerId) {


this.manufacturerId = manufacturerId;
(continues on next page)

1.2. Understanding instance objects 9


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

public String getReservedId() {


return reservedId;
}

public void setReservedId(String reservedId) {


this.reservedId = reservedId;
}

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

// The IBecon class represents beacon devices for the iBeacon␣


,→ protocol
z

public class IBeacon extends FeasyBeacon {


en
Sh

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;
(continues on next page)

1.2. Understanding instance objects 10


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

public void setCompany(String company) {


this.company = company;
}

public String getType() {


return type;
}

d .
Lt
public void setType(String type) {
this.type = type;

.,
}

Co
public String getDataLength() {
return dataLength;
om
}
yc

public void setDataLength(String dataLength) {


this.dataLength = dataLength;
as

}
Fe

public int getMajor() {


n

return major;
he

}
z
en

public void setMajor(int major) {


this.major = major;
Sh

public int getMinor() {


return minor;
}

public void setMinor(int minor) {


this.minor = minor;
}

(continues on next page)

1.2. Understanding instance objects 11


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {


this.uuid = uuid;
}

public int getRssi() {

d .
return rssi;

Lt
}

.,
public void setRssi(int rssi) {

Co
this.rssi = rssi;
}
}
om
yc

1.2.5 The Monitor class represents a type of monitor device, including


as

its temperature, humidity, battery level, and name attributes


Fe

// The Monitor class represents a type of monitor device, including␣


n

,→ its temperature, humidity, battery level, and name attributes


he

public class Monitor extends FeasyBeacon {


z

private String temperature; // Temperature value


en

private String humidity; // Humidity value


Sh

private int battery; // battery level


private String name; // Monitor Name

public String getTemperature() {


return temperature;
}

public void setTemperature(String temperature) {


this.temperature = temperature;
}
(continues on next page)

1.2. Understanding instance objects 12


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)

public String getHumidity() {


return humidity;
}

public void setHumidity(String humidity) {


this.humidity = humidity;
}

d .
@Override

Lt
public int getBattery() {
return battery;

.,
}

Co
@Override
public void setBattery(int battery) {
om
this.battery = battery;
}
yc

public String getName() {


as

return name;
Fe

}
n

public void setName(String name) {


he

this.name = name;
}
z
en

}
Sh

1.2.6 The FeasyBeacon class represents a beacon device, including its re-
lated properties and configuration information

// The FeasyBeacon class represents a beacon device, including its␣


,→ related properties and configuration information
public class FeasyBeacon implements Serializable {

// Beacon type constant


(continues on next page)

1.2. Understanding instance objects 13


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


public static final String BEACON_TYPE_EDDYSTONE_URL = "URL";
public static final String BEACON_TYPE_EDDYSTONE_UID = "UID";
public static final String BEACON_TYPE_EDDYSTONE_TLM = "TLM";
public static final String BEACON_TYPE_I_BEACON = "iBeacon";
public static final String BEACON_TYPE_ALTBEACON = "AltBeacon";
public static final String BEACON_TYPE_NULL = "";
public static final int BEACON_COUNT = 10;
public static final String ENCRYPT_BEACON = "Beacon";
public static final String ENCRYPT_UNIVERSAL = "Universal";

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

private String version; // Version information


private String deviceName; // Device Name
as

private String deviceAddress; // Device address


Fe

private int battery = -1; // battery level


private String encryptionWay; // Encryption method
n
he

public int getBattery() {


return battery;
z
en

}
Sh

public void setBattery(int battery) {


this.battery = battery;
}

public boolean getConnectable() {


return connectable;
}

public void setConnectable(boolean connectable) {


this.connectable = connectable;
(continues on next page)

1.2. Understanding instance objects 14


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

public String getVersion() {


return version;
}

public void setVersion(String version) {


this.version = version;
}

d .
Lt
public String getDeviceName() {
return deviceName;

.,
}

Co
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
om
}
yc

public String getDeviceAddress() {


return deviceAddress;
as

}
Fe

public void setDeviceAddress(String deviceAddress) {


n

this.deviceAddress = deviceAddress;
he

}
z
en

public String getModule() {


return module;
Sh

public void setModule(String module) {


this.module = module;
}

public String getEncryptionWay() {


return encryptionWay;
}

(continues on next page)

1.2. Understanding instance objects 15


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


public void setEncryptionWay(String encryptionWay) {
this.encryptionWay = encryptionWay;
}

public boolean getKeyConfig() {


return keyConfig;
}

public void setKeyConfig(boolean keyConfig) {

d .
this.keyConfig = keyConfig;

Lt
}

.,
public boolean getGSensor() {

Co
return gSensor;
}
om
public void setGSensor(boolean gSensor) {
this.gSensor = gSensor;
yc

}
as

public boolean getBuzzer() {


Fe

return buzzer;
}
n
he

public void setBuzzer(boolean buzzer) {


this.buzzer = buzzer;
z
en

}
Sh

public boolean getLed() {


return led;
}

public void setLed(boolean led) {


this.led = led;
}

public boolean getNfc() {


return nfc;
(continues on next page)

1.2. Understanding instance objects 16


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

public void setNfc(boolean nfc) {


this.nfc = nfc;
}

public boolean isLongRange() {


return longRange;
}

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

// The BeaconBean class is used to represent the attribute␣


,→ information of Bluetooth beacons
n

public class BeaconBean implements Serializable {


he

private String index; // index


private String beaconType; // Beacon type (iBeacon, Eddystone_URL,
z
en

,→ 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)

1.2. Understanding instance objects 17


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


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␣

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

private String txpower = "2"; // Beacon TX power, default value␣


of 2
as

,→

private String phy = "0"; // Physical layer, default value is 0


Fe

public BeaconBean() {
n

}
he

public BeaconBean(String index, String beaconType) {


z
en

this.index = index;
this.beaconType = beaconType;
Sh

public String getIndex() {


return index;
}

public void setIndex(String index) {


this.index = index;
}

(continues on next page)

1.2. Understanding instance objects 18


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


public String getBeaconType() {
return beaconType;
}

public void setBeaconType(String beaconType) {


this.beaconType = beaconType;
}

public String getUuid() {

d .
return uuid;

Lt
}

.,
public void setUuid(String uuid) {

Co
this.uuid = uuid;
}
om
public String getMajor() {
return major;
yc

}
as

public void setMajor(String major) {


Fe

this.major = major;
}
n
he

public String getMinor() {


return minor;
z
en

}
Sh

public void setMinor(String minor) {


this.minor = minor;
}

public String getUrl() {


return url;
}

public void setUrl(String url) {


this.url = url;
(continues on next page)

1.2. Understanding instance objects 19


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

public String getNameSpace() {


return nameSpace;
}

public void setNameSpace(String nameSpace) {


this.nameSpace = nameSpace;
}

d .
Lt
public String getInstance() {
return instance;

.,
}

Co
public void setInstance(String instance) {
this.instance = instance;
om
}
yc

public String getReserved() {


return reserved;
as

}
Fe

public void setReserved(String reserved) {


n

this.reserved = reserved;
he

}
z
en

public String getId1() {


return id1;
Sh

public void setId1(String id1) {


this.id1 = id1;
}

public String getId2() {


return id2;
}

(continues on next page)

1.2. Understanding instance objects 20


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


public void setId2(String id2) {
this.id2 = id2;
}

public String getId3() {


return id3;
}

public void setId3(String id3) {

d .
this.id3 = id3;

Lt
}

.,
public String getManufacturerId() {

Co
return manufacturerId;
}
om
public void setManufacturerId(String manufacturerId) {
this.manufacturerId = manufacturerId;
yc

}
as

public String getManufacturerReserved() {


Fe

return manufacturerReserved;
}
n
he

public void setManufacturerReserved(String manufacturerReserved) {


this.manufacturerReserved = manufacturerReserved;
z
en

}
Sh

public String getPower() {


return power;
}

public void setPower(String power) {


this.power = power;
}

public boolean isConnectable() {


return connectable;
(continues on next page)

1.2. Understanding instance objects 21


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


}

public void setConnectable(boolean connectable) {


this.connectable = connectable;
}

public boolean isEnable() {


return enable;
}

d .
Lt
public void setEnable(boolean enable) {
this.enable = enable;

.,
}

Co
public String getVersion() {
return version;
om
}
yc

public void setVersion(String version) {


this.version = version;
as

}
Fe

public int getInterval() {


n

return interval;
he

}
z
en

public void setInterval(int interval) {


this.interval = interval;
Sh

public String getParentName() {


return parentName;
}

public void setParentName(String parentName) {


this.parentName = parentName;
}

(continues on next page)

1.2. Understanding instance objects 22


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


public String getTxpower() {
return txpower;
}

public void setTxpower(String txpower) {


this.txpower = txpower;
}

public String getPhy() {

d .
return phy;

Lt
}

.,
public void setPhy(String phy) {

Co
this.phy = phy;
}
}
om
yc

1.3 Quick Integration (Android)


as
Fe

1.3.1 Integrated SDK


n

• If you have not yet installed Android Studio, please visit [Android official website]
z he

1.3.2 Create Android project


en

• Create a new project in Android Studio.


Sh

1.3. Quick Integration (Android) 23


FeasyBeacon SDK Android User Guide 3.3.6

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

implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')


Fe

}
n
he

1.3.5 Configure the AndroidManifest.xml file


z

• In your application, permission needs to be granted in the AndroidManifest.xml file.


en

Please add the following code to your application manifest file.


Sh

<?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"␣
(continues on next page)

1.3. Quick Integration (Android) 24


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


,→ />

<!-- Location permissions -->


<uses-permission android:name="android.permission.ACCESS_COARSE_
,→ LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_
,→ LOCATION" />

<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

,→ android:enabled="true" android:exported="false" />


n

</application>
he

</manifest>
z
en
Sh

1.4 Example of interface usage method

1.4.1 Responsible for managing Bluetooth operations and related data

object BluetoothRepository {

// Selected Bluetooth device mapping


val selectedDeviceMap = LinkedHashMap<String, Any>()
// Module number
(continues on next page)

1.4. Example of interface usage method 25


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


var mModule = 0
// Version range
var mVersionRange: Range<Int>? = null
// Discovered Bluetooth device list
var mDevices = mutableListOf<BluetoothDeviceWrapper>()
// List for callbacks
private val mCallbacks = mutableListOf<FscBleCallback>()
// Bluetooth connection PIN code
var mConnectPin = "000000"

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

* Check if Bluetooth is enabled


Fe

*/
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)

1.4. Example of interface usage method 26


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


*/
fun stopScan() = mFscBeaconCentralApi.stopScan()

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

fun isBeaconInfoFull() = mFscBeaconCentralApi.isBeaconInfoFull


z
en

/**
* 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)

1.4. Example of interface usage method 27


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


mFscBeaconCentralApi.deleteBeaconInfo(beaconBean.index)
mCallbacks.forEach { it.onDeleteBeaconInfo(beaconBean) }
}

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

fun restore() = mFscBeaconCentralApi.restore()

/**
* Query or set firmware key
*/
fun setFirmwareKey(command : String) = mFscBeaconCentralApi.
,→ setFirmwareKey(command)

/**
* Set application key
(continues on next page)

1.4. Example of interface usage method 28


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


*/
fun setAppKey(key: String) = mFscBeaconCentralApi.setAppKey(key)

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

* Check DFU files


he

* @param dfuFile
*/
z
en

fun checkDfuFile(dfuFile: ByteArray) = mFscBeaconCentralApi.


,→ checkDfuFile(dfuFile)!!
Sh

/**
* Starting OTA update
* @param dfuFile
* @param reset
*/
fun startOtaUpdate(dfuFile: ByteArray, reset: Boolean) =␣
,→ mFscBeaconCentralApi.startOtaUpdate(dfuFile, reset)

/**
(continues on next page)

1.4. Example of interface usage method 29


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


* Set Beacon Information
*/
fun setBeaconInfo() = mFscBeaconCentralApi.saveBeaconInfo()

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

} catch (e: Exception) {


e.printStackTrace()
as

}
Fe

}
n

/**
he

* Unregister View Callback


* @param callback
z
en

*/
fun unRegisterViewCallback(callback: FscBleCallback) {
Sh

try {
mCallbacks.remove(callback)
} catch (e: Exception) {
e.printStackTrace()
}
}

/**
* Get device information
* @param feasyBeacon
(continues on next page)

1.4. Example of interface usage method 30


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


* @param isTxPower
*/
fun getDeviceInfo(feasyBeacon: FeasyBeacon, isTxPower: Boolean) {
mFscBeaconCentralApi.getDeviceInfo(feasyBeacon, isTxPower)
}

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

// Connection progress update


override fun connectProgressUpdate(device: BluetoothDevice?,␣
as

,→ status: Int) {
Fe

mCallbacks.forEach { it.onConnectProgressUpdate(status) }
}
n
he

// Discovering Bluetooth peripherals


override fun blePeripheralFound(device:␣
z
en

,→ BluetoothDeviceWrapper?, rssi: Int, record: ByteArray?) {


// If the device is empty, return
Sh

if (device == null) return

try {
// Check if the device is iBeacon, EddystoneBeacon,␣
,→ or AltBeacon
if (device.iBeacon != null || device.eddystoneBeacon !
,→ = null || device.altBeacon != null) {
notifyCallbacks { it.onBeacon(device) }
}

(continues on next page)

1.4. Example of interface usage method 31


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


// If the device contains monitoring data
device.monitor?.let {
notifyCallbacks { it.onSensor(device) }
}

// If the device contains FeasyBeacon module data


device.feasyBeacon?.module?.let {
notifyCallbacks { it.onSetting(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

} catch (e: Exception) {


Fe

e.printStackTrace()
}
n

}
he

}
z
en

// Bluetooth peripheral connected


override fun blePeripheralConnected(gatt: BluetoothGatt?,␣
Sh

,→ device: BluetoothDevice?) {
mCallbacks.forEach { it.onConnectedSuccess() }
}

// Bluetooth peripheral disconnected


override fun blePeripheralDisconnected(gatt: BluetoothGatt?,␣
,→ device: BluetoothDevice?) {
mCallbacks.forEach { it.onDisconnect() }
}

(continues on next page)

1.4. Example of interface usage method 32


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


// AT command callback
override fun atCommandCallBack(command: String?, param:␣
,→ String?, status: String?) {
mCallbacks.forEach { it.onAtCommandCallBack(command,␣
,→ param, status) }
}

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

override fun packetReceived(


he

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

// Received read response


(continues on next page)

1.4. Example of interface usage method 33


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


override fun readResponse(
gatt: BluetoothGatt?,
device: BluetoothDevice?,
service: BluetoothGattService?,
ch: BluetoothGattCharacteristic?,
strValue: String?,
hexString: String?,
rawValue: ByteArray?,
timestamp: String?

d .
) {}

Lt
// Send packet progress

.,
override fun sendPacketProgress(

Co
gatt: BluetoothGatt?,
device: BluetoothDevice?,
ch: BluetoothGattCharacteristic?,
om
percentage: Int,
sendByte: ByteArray?
yc

) {}
as

// OTA progress update


Fe

override fun otaProgressUpdate(percentage: Int, status: Int) {


mCallbacks.forEach { it.onOtaProgressUpdate(percentage) }
n

}
he

// Received device information


z
en

override fun onDeviceInfoReceived(parameterName: String?,␣


,→ parameter: Any?) {
Sh

mCallbacks.forEach { it.onDeviceInfo(parameterName,␣
,→ parameter) }
}
}
}

1.4. Example of interface usage method 34


FeasyBeacon SDK Android User Guide 3.3.6

1.4.2 SUOTA SDK Upgrade Usage Example

class SuotaActivity : BaseActivity<ActivitySuotaBinding>(),


DeviceInfoFragment.OnDeviceInfoFragmentInteractionListener,
AvailableFirmwareFragment.
,→ OnAvailableFirmwareFragmentInteractionListener,
UpdateFirmwareFragment.OnUpdateFirmwareFragmentInteractionListener,
BaseSuotaFragment.OnBaseSuotaFragmentInteractionListener{

private lateinit var suotaFile: SuotaFile

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

//Set upgrade file


override fun onFirmwareSelected(suotaFile: SuotaFile?) {
n

suotaManager.suotaFile = suotaFile
he

suotaManager.initializeSuota(240, 3, 0, 1, 4, 2)
}
z
en

//Start firmware upgrade


Sh

override fun startSuotaProtocol() {


suotaManager.startUpdate()
}

//A callback class used to handle SUOTA (wireless firmware upgrade)␣


,→ events.
class SuotaCallback(@NonNull private val suotaActivityRef:␣
,→ SuotaActivity): SuotaManagerCallback() {
(continues on next page)

1.4. Example of interface usage method 35


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)

// Called when the connection status changes.


override fun onConnectionStateChange(newStatus: SuotaProfile.
,→ SuotaManagerStatus) {

// When a service is discovered, it is called.


override fun onServiceDiscovered() {

d .
Lt
}

.,
// Called when reading feature values.

Co
override fun onCharacteristicRead(characteristicGroup:␣
,→ SuotaProfile.CharacteristicGroup, characteristic:␣
,→ BluetoothGattCharacteristic) {
om
}
yc

// Called when reading device information is complete.


as

override fun onDeviceInfoReadCompleted(status: SuotaProfile.


Fe

,→ DeviceInfoReadStatus) {
n

}
he

// Called when the device is ready for SUOTA.


z
en

override fun onDeviceReady() {


Sh

// 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,␣
(continues on next page)

1.4. Example of interface usage method 36


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


,→ 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) {

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

// Called when sending a restart command.


override fun onRebootSent() {
n
he

}
z
en

// Update speed statistics during the upload process.


override fun updateSpeedStatistics(current: Double, max: Double,
Sh

,→ 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.


(continues on next page)

1.4. Example of interface usage method 37


FeasyBeacon SDK Android User Guide 3.3.6

(continued from previous page)


override fun pendingRebootDialog(rebootDialog:␣
,→ SupportCustomDialogFragment) {

d .
Lt
.,
Co
om
yc
as
Fe
n
z he
en
Sh

1.4. Example of interface usage method 38

You might also like