To allow your app to receive the status of the different services used by to the SDK, a ProximityHealthCheckListener must be registered to the HerowInitializer.

Using these statuses, you can adapt the user interface depending of the availability of the various services used by the SDK.

Register the ProximityHealthCheckListener

  • Open an Activity

  • Make the Activity implementing the ProximityHealthCheckListener

public class MainActivity extends AppCompatActivity implements ProximityHealthCheckListener
  • In the onResume method, register the Activity to the HerowInitializer using the registerProximityHealthCheckListener method
protected void onResume(){
    super.onResume();
    HerowInitializer.getInstance().registerProximityHealthCheckListener(this);
}

Note:

You can also decide to make your application notify only about the status update of specific services. This can be achieved by adding at end of the method, the list of the services for which your application must be notified in the event of an update:

protected void onResume(){
   super.onResume();
   HerowInitializer.getInstance().registerProximityHealthCheckListener(this, 1, 2);
}

In this example, the Activity will be notified about the status update of the services 1 and 2

Unregister the ProximityHealthCheckListener

  • In the onPause method, register the Activity to the HerowInitializer using the unregisterProximityHealthCheckListener method
protected  void onPause() {
    super.onPause();
    HerowInitializer.getInstance().unregisterProximityHealthCheckListener(this);
}

Note:

You can find a concrete implementation of the registration process in the source code of the the quickstart tutorial in our github repo.

Implements the onProximityHealthCheckUpdate method

The onProximityHealthCheckUpdate method takes one parameter called HealthStatus. This object possesses two variables:

  • isDown: a boolean which allows you to know if any services have been touched.
  • Map<Integer, ServiceStatus>: a map of all the services available in the SDK associated with their type. You can consult the exhaustive list of services and their type in the the services document.

The ServiceStatus object contains:

  • isDown: the current status of the service.
  • List: a list of Status. A status contains a subtype and the associated message to it.

As soon as an error occurs in a service, the isDown Boolean is set to true and an error is added to the list of status. You just have to loop, on every service and adapt your interface according to the current status.

Pratical example

Let's see a simple example to clear your minds!

We want to check if the bluetooth has any issues.

We check the current code of the bluetooth service: it's 3.

So to be able to react of any bluetooth issues, we just need to monitor the type 3 and listen the subtype which we are interested in.

@Override
public void onProximityHealthCheckUpdate(HealthStatus healthStatus) {
    if (healthStatus.isDown()) {
        for (ServiceStatus serviceStatus : healthStatus.getServiceStatusMap().values()) {
            if (serviceStatus.isDown()) {
                if (serviceStatus.getType() == 3) {
                    if (serviceStatus.containsStatus(32)) {
                        textViewErrors.setText("Your device does not support Bluetooth LE.");
                    } else {
                        textViewErrors.setText("The bluetooth is unactive, please activate it to let the scan begin");
                    }
                }
            }
        }   
    } else {
        textViewErrors.setText("");
    }
}