Skip to content
On this page

PPG Device Scanner

The SDK provides an API to scan for nearby PPG devices, based on a specified PPGDeviceType. The results obtained during the scan can be utilized later to create PPG Device sessions with any device from the list.

Creating a PPG Device Scanner

PPGDeviceScanner can be created using the PPGDeviceScannerFactory. In the following sample, a scanner searching for PPGDeviceType.POLAR is created, and the current class implements PPGDeviceScannerListener

Kotlin
try {
    val ppgDeviceType = PPGDeviceType.POLAR
    val listener = this
    val scanner = PPGDeviceScannerFactory(applicationContext, ppgDeviceType, listener)
} catch (e: HealthMonitorException) {
    Log.i("ERROR", "Received Error. Domain: ${e.domain} Code: ${e.errorCode}")
}
Java
try {
    PPGDeviceType ppgDeviceType = PPGDeviceType.POLAR;
    PPGDeviceScannerListener listener = this;
    PPGDeviceScanner scanner = PPGDeviceScannerFactory(applicationContext, ppgDeviceType, listener);
} catch (HealthMonitorException e) {
    Log.i("ERROR", "Received Error. Domain: "+ e.getDomain() +" Code: "+ e.getErrorCode());
}

Starting a scan for PPG Devices

To initiate a scan, call the start method. If the method is called without a timeoutDuration parameter, or with a value of 0 or below, the default timeout of 60 seconds is used. The timeout duration should be specified in seconds.

If a scanner is already performing a scan, calling start will first stop the current scan before starting a new one.

In the following example, scanner.start is called with a timeoutDuration of 30 seconds.

Kotlin
try {
    val timeoutDuration = 30L
    scanner.start(timeoutDuration)
} catch (e: HealthMonitorException) {
    Log.i("ERROR", "Received Error. Domain: ${e.domain} Code: ${e.errorCode}")
}
Java
try {
    long timeoutDuration = 30L;
    scanner.start(timeoutDuration);
} catch (HealthMonitorException e) {
    Log.i("ERROR", "Received Error. Domain: "+ e.getDomain() +" Code: "+ e.getErrorCode());
}

Receiving results during a scan

To receive PPGDevice objects, the application should implement the onPPGDeviceDiscovered method as part of PPGDeviceScannerListener.

The PPGDevice objects obtained through this method represent nearby PPG devices found by the scanner during the scan. These devices are potential candidates for establishing a session later, utilizing their deviceID field.

Kotlin
override fun onPPGDeviceDiscovered(ppgDevice: PPGDevice) {  
    runOnUiThread {
        // ppgDevice.type     -      The PPGDeviceType of the found device
        // ppgDevice.deviceID -      The ID to use later when creating a PPG Device Session
    }
}

override fun onPPGDeviceScanFinished() {
    runOnUiThread {
        // Called when a scan is finished or stopped
    }
}
Java
@Override  
public void onPPGDeviceDiscovered(@NonNull PPGDevice ppgDevice) {
    runOnUiThread(() -> {
        // ppgDevice.getType()     -      The PPGDeviceType of the found device
        // ppgDevice.getDeviceID() -      The ID to use later when creating a PPG Device Session
    });
}

@Override
public void onPPGDeviceScanFinished() {
    runOnUiThread(() -> {
        // Called when a scan is finished or stopped
    });
}

Note

Please note that devices found during the scan do not guarantee a successful session establishment. Certain factors, such as the device having a version lower than the allowed minimum in the SDK, can cause a session to fail.

For more information on potential errors during session establishment, refer to the Alerts List.

Stopping a scan for PPG Devices

During a scan, it will automatically stop when the timeout period ends. Additionally, the application can manually stop the scan by calling the stop method.

Kotlin
scanner.stop()
Java
scanner.stop();

When a scan timeout is finished, the method onPPGDeviceScanFinished (part of PPGDeviceScannerListener) is called.

Kotlin
override fun onPPGDeviceDiscovered(ppgDevice: PPGDevice) {
    runOnUiThread {
        // ppgDevice.type     -      The PPGDeviceType of the found device
        // ppgDevice.deviceID -      The ID to use later when creating a PPG Device Session
    }
}

override fun onPPGDeviceScanFinished() {  
    runOnUiThread {
        // Called when a scan is finished or stopped
    }
}
Java
@Override
public void onPPGDeviceDiscovered(@NonNull PPGDevice ppgDevice) {
    runOnUiThread(() -> {
        // ppgDevice.getType()     -      The PPGDeviceType of the found device
        // ppgDevice.getDeviceID() -      The ID to use later when creating a PPG Device Session
    });
}

@Override  
public void onPPGDeviceScanFinished() {
    runOnUiThread(() -> {
        // Called when a scan is finished or stopped
    });
}

Important

Note that the methods of PPGDeviceScannerListener are called on a background thread. The application must switch to the UI thread in order to perform UI updates.