Android Connected document

SDK Support Platform

  • Android 5.0 and above version

Proguard

-keep class cn.icomon.icdevicemanager.ICDeviceManager { *; }
-keep class cn.icomon.icdevicemanager.ICBluetoothSystem { *; }
-keep public function cn.icomon.icdevicemanager.ICBluetoothSystem$ICBluetoothDelegate { *; }
-keep public class cn.icomon.icdevicemanager.ICBluetoothSystem$ICOPBleCharacteristic { *; }
-keep public enum cn.icomon.icdevicemanager.ICBluetoothSystem$ICOPBleWriteDataType { *; }
-keep class cn.icomon.icdevicemanager.manager.setting.ICSettingManagerImpl { *; }
-keep class cn.icomon.icdevicemanager.manager.algorithms.ICBodyFatAlgorithmsImpl { *; }
-keep class cn.icomon.icdevicemanager.ICDeviceManagerDelegate { *; }
-keep class cn.icomon.icdevicemanager.model.** { *; }
-keep class cn.icomon.icdevicemanager.ICDeviceManagerSettingManager { *; }
-keep public function cn.icomon.icdevicemanager.ICDeviceManagerSettingManager$ICSettingCallback { *; }
-keep class com.icomon.icbodyfatalgorithms.** { *; }
-keep class cn.icomon.icbleprotocol.** { *; }
-keep class cn.icomon.icdevicemanager.ICBodyFatAlgorithmsManager { *; }
-keep class cn.icomon.icdevicemanager.ICBluetoothSystem.** { *; }
-keep class cn.icomon.icdevicemanager.callback.** { *; }

Permissions

AndroidManifest.xml declaration

<uses-permission 
    android:name="android.permission.BLUETOOTH"
    android:maxSdkVersion="30"/>
<uses-permission 
    android:name="android.permission.BLUETOOTH_ADMIN" 
    android:maxSdkVersion="30"/>
<uses-permission 
    android:name="android.permission.ACCESS_COARSE_LOCATION" 
    android:maxSdkVersion="30"/>
<uses-permission
     android:name="android.permission.ACCESS_FINE_LOCATION" 
     android:maxSdkVersion="30"/>
<uses-permission 
    android:usesPermissionFlags="neverForLocation"  
    android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission 
    android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission 
    android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-feature 
    android:name="android.hardware.bluetooth_le" 
    android:required="true"/>

Dynamically obtain permission instructions:

  • 1. Android 6 to Android 11 need to dynamically obtain ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions
  • 2. Android 10 to Android 11 Bluetooth scanning needs to turn on the location switch
  • 3. Android 12 and above needs to dynamically obtain BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions

Refrence from Android: https://developer.android.com/guide/topics/connectivity/bluetooth

Code example

Check whether you have obtained the permissions required for Bluetooth scanning and connection

    private boolean checkBLEConnectionPermission() {
        boolean isGranted = false;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
                isGranted = true;
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                isGranted = true;
            }
        } else {
            isGranted = true;
        }
        return isGranted;
    }

Request permissions required for Bluetooth scanning and connection

private void requestBLEConnectionPermission() {
    String[] arrayPermission;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
        arrayPermission = new String[]{Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN};
    } else {
        arrayPermission = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};
    }
    ActivityCompat.requestPermissions(this, arrayPermission, CODE_REQUEST_PERMISSION);
}

Android 10 to Android 11 Location Switch related

public static boolean needOpenGpsSwitch() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Build.VERSION.SDK_INT <= Build.VERSION_CODES.R;
}

public static boolean isOpenGpsSwitch(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        return true;
    } else {
        return false;
    }
}

Import SDK

The SDK uses Java and C++ mixed development, and provides aar package for import.

The importing steps are as follows:

Import SDK Import SDK Import SDK Import SDK

SDK Access process

Initialize the SDK

Call ICDeviceManager.shared().initMgrWithConfig(cfg) to initialize the SDK. Before initialization, it is recommended to call ICDeviceManager.shared().setDelegate(delegate) to set up the proxy object. Otherwise, some callbacks may be lost.

Eg.

ICDeviceManager.shared().setDelegate(this);
ICDeviceManager.shared().initMgrWithConfig(cfg);

Scan device

After the SDK is initialized, if you need to find nearby devices, you can call the scanDevice function to scan the devices:

ICDeviceManager.shared().scanDevice(delegate);

The device will call back through the scan callback proxy object. (Before calling the scan function, please make sure Bluetooth is turned on, otherwise the function will not take effect.If Bluetooth is turned off during scanning, turning on Bluetooth and call the function again, the SDK will not automatically turn on scanning).

Note: If you already know the mac address of the device, you can directly transfer and add device function without calling the scan function. The SDK will automatically connect to this device internally.

Stop scanning

The scanning device function is called. After the device has been found, please call to stop scanning (sdk will not stop automatically):

ICDeviceManager.shared().stopScan();

Add device

If the device has been found, call the add device function:

ICDeviceManager.shared().addDevice(device,addCallback);

The function can be used to connect the device to the SDK and receive device data (please ensure that the device is powered on, If the device is disconnected, the SDK automatically connects to the device. There is no need to re-add devices or scan devices).

Remove device

When you do not want the SDK to connect and receive device data, you can call the remove device function:

ICDeviceManager.shared().removeDevice(device,removeCallback);

Update user information

Because the user's bodyfat data and some other data need to be calculated, the App needs to call the update user information interface:

ICDeviceManager.shared().updateUserInfo(userInfo);

Log directory

If the SDK cannot receive data or the connection is abnormal, please send us the SDK log and obtain the SDK log directory:

ICDeviceManager.shared().getLogPath();

Device setting function

Some devices support setting units or calories. These setting interfaces are obtained by:

ICDeviceManager.shared().getSettingManager();

Body fat algorithm function

Get the body fat algorithm function:

ICDeviceManager.shared().getBodyFatAlgorithmsManager();
GUANGDONG WELLAND TECHNOLOGY CO.,LTD All Right ReservedUpdate time: 2024-07-20 11:40:06

results matching ""

    No results matching ""

    results matching ""

      No results matching ""