Last Updated on : 2024-09-03 07:51:38download
System requirements: Android 4.3 or later. Smart Industry App SDK works with Android 6.0 and later.
Manifest permissions:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- Android 12 added -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
Bluetooth permission precheck: It is performed before Bluetooth scanning and connection. Otherwise, the app cannot use Bluetooth as expected.
Smart Industry App SDK does not provide the logic for precheck. You can implement it on your own.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
mode |
ActivatorMode |
Yes | The pairing mode. |
Example
BLEWIFIActivator blewifiActivator = (BLEWIFIActivator) ActivatorService.activator(ActivatorMode.BLE_WIFI);
IDiscovery
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
mode |
DiscoveryMode |
Yes | The scanning mode. |
Example
IDiscovery iDiscovery = ActivatorService.discovery(DiscoveryMode.BLE_WIFI);
Example
DiscoveryParams.Builder builder = new DiscoveryParams.Builder();
builder.setTimeout(600_000);
DiscoveryParams discoveryParams = new DiscoveryParams(builder);
iDiscovery.setParams(discoveryParams);
IDiscoveryListener
to listen for scanning resultParameters
IBluetoothDevice
data model
Parameter | Type | Description |
---|---|---|
getId | Function | Get the ID of the Bluetooth device. |
getName | Function | Get the name of the Bluetooth device. |
getData | Function | Get the device data. |
getConfigType | Function | Get the configuration type.
|
getAddress | Function | Get the Bluetooth address of the device. |
getDeviceType | Function | Get the type of the device. |
getUUID | Function | Get the UUID of the device. |
getMAC | Function | Get the MAC address of the device. |
getProductId | Function | Get the product ID for the device. |
isBind | Function | Determine if the device has been bound. |
getFlag | Function |
|
getDeviceType
indicates the type of device to be paired.
Value of getDeviceType |
getConfigType | Device type |
---|---|---|
200 | config_type_single | Bluetooth device |
300 | config_type_single | Bluetooth device |
301 | config_type_wifi | Wi-Fi and Bluetooth combo device |
304 | config_type_wifi | Wi-Fi and Bluetooth combo device that supports pairing over Bluetooth if a Wi-Fi connection is unavailable |
400 | config_type_single | Bluetooth device |
401 | config_type_wifi | Wi-Fi and Bluetooth combo device |
404 | config_type_wifi | Wi-Fi and Bluetooth combo device that supports pairing over Bluetooth if a Wi-Fi connection is unavailable |
Example
IDiscovery iDiscovery = ActivatorService.discovery(DiscoveryMode.BLE_WIFI);
iDiscovery.setListener(new IDiscoveryListener() {
@Override
public void didDiscover(@NonNull IDiscoveryDevice iDiscoveryDevice) {
if (iDiscoveryDevice instanceof IBluetoothDevice){
((IBluetoothDevice) iDiscoveryDevice).getAddress();
((IBluetoothDevice) iDiscoveryDevice).getId();
((IBluetoothDevice) iDiscoveryDevice).getDeviceType();
}
}
});
// Start scanning.
iDiscovery.startDiscovery();
// Stop scanning.
iDiscovery.stopDiscovery();
Get the parameters from the result of the scanning listener.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
address | String | Yes | The address of the Bluetooth device. |
assetId | String | Yes | The ID of the specified asset or space. |
token | String | Yes | The token of the device. |
pwd | String | No | The password of the Wi-Fi network. |
uuid | String | Yes | The UUID of the device. |
ssid | String | No | The SSID of the Wi-Fi network. |
mac | String | No | The MAC address of the device. |
time | long | No | The activation timeout, in milliseconds. |
phase1Timeout | long | No | The timeout for device activation and pairing in the cloud, default value: 60000, in milliseconds. |
onlyConnectBle | Boolean | No | Indicates whether to connect and activate the device over Bluetooth only, default value: false. |
BLEWIFIActivatorParams params = new BLEWIFIActivatorParams.Builder()
.setAddress("address")
.setAssetId("assetId")
.setToken("token")
.setPwd("pwd")
.setUuid("uuid")
.setSsid("ssid")
.setMac("mac")
.setTimeout(time)
.build();
blewifiActivator.setParams(params);
IActivatorListener
to listen for pairing resultExample
blewifiActivator.setListener(new IActivatorListener() {
@Override
public void onSuccess(@Nullable IDevice iDevice) {
Log.d(TAG, "onSuccess: ");
}
@Override
public void onError(@NonNull String s, @NonNull String s1) {
Log.d(TAG, "onError: ");
}
});
// Added enhanced Activator listener, maintaining compatibility with the previous version of the listener.
blewifiActivator.setListener(new IExtMultiModeActivatorListener() {
@Override
public void onActivatorStatePauseCallback(@NonNull String uuid, int configStage, int status) {
}
@Override
public void onSuccess(@Nullable IDevice iDevice) {
}
@Override
public void onError(@NonNull String s, @NonNull String s1) {
}
});
Description of onActivatorStatePauseCallback
:
Pairing stage configStage |
Description | Pairing status |
---|---|---|
0 | Activation of pairing |
|
1 | Delegate activation |
|
2 | Connection to the network |
|
3 | Activation stage |
|
This method starts device pairing.
Example
blewifiActivator.start();
Example
blewifiActivator.stop();
Example
blewifiActivator.destroy();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback