Last Updated on : 2024-09-03 07:08:00download
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.
Before scanning and connection, the app checks if it is allowed to access location services.
Check if the phone’s Bluetooth is turned on.
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
BLEActivator bleActivator = (BLEActivator) ActivatorService.activator(ActivatorMode.BLE);
IDiscovery
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
mode |
DiscoveryMode |
Yes | The scanning mode. |
Example
IDiscovery iDiscovery = ActivatorService.discovery(DiscoveryMode.BLE);
Example
DiscoveryParams discoveryParams = new DiscoveryParams(new DiscoveryParams.Builder().setTimeout(600_000));
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);
iDiscovery.setListener(new IDiscoveryListener() {
@Override
public void didDiscover(@NonNull IDiscoveryDevice iDiscoveryDevice) {
if (iDiscoveryDevice instanceof IBluetoothDevice){
((IBluetoothDevice) iDiscoveryDevice).getAddress();
((IBluetoothDevice) iDiscoveryDevice).getId();
}
}
});
// 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. |
deviceType | Int | No | The type of the device. |
uuid | String | Yes | The UUID of the device. |
productId | String | Yes | The product ID of the device. |
time | long | No | The activation timeout, in milliseconds. |
BLEActivatorParams params = new BLEActivatorParams.Builder()
.setAddress("address")
.setAssetId("assetId")
.setDeviceType(deviceType)
.setUuid("uuid")
.setProductId("productId")
.setTimeout(time)
.build();
bleActivator.setParams(params);
IActivatorListener
to listen for pairing resultExample
bleActivator.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: ");
}
});
This method starts device pairing.
Example
bleActivator.start();
Example
bleActivator.stop();
Example
bleActivator.destroy();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback