Connectivity to Platform

This section describes how to check the connectivity of the Smarter AI Camera Platform. Connectivity to platform is necessary to get service from the platform.

Getting Connectivity Status

To get the connection status of your device, call the hasConnectivity() method of Access class which returns a Boolean value indicating the connectivity status.

boolean isConnectionAvailable = AnyConnectApi.get().getAccess().hasConnectivity();
boolean isConnectionAvailable = access->hasConnectivity();

Getting Call-back for Connectivity Change

To get notified for connectivity changes, follow steps below.

📘

Android

  1. To get connectivity change events, call enableConnectivityChangeNotification() method from Access class once after the Access build is finished.
AnyConnectApi.get().getAccess().enableConnectivityChangeNotification();
  1. Next, attach interface Access.ConnectivityChangeListener to Access by calling RegisterConnectivityListener(ConnectivityChangeListener listener) method.
AnyConnectApi.get().getAccess().RegisterConnectivityListener(connectivityChangeListener);
  1. Once the interface is registered to the Access library, connectivity change events will start getting posted to the onConnectivityChange(Access.PresenceStatus status) method of the registered interface.
connectivityChangeListener = new Access.ConnectivityChangeListener() {
    @Override
    public void onConnectivityChange(Access.PresenceStatus status) {
        // status indicates the connectivity status of your endpoint.
        // See JavaDoc for more details of Access.PresenceStatus
    }
};

The status of onConnectivityChange method defines the connectivity status of your device.

📘

iOS

  1. To get connectivity change events, call registerSelfConnectionChangeCallback(SelfConnectionCallback callback) method of the Access class to register connectivity change callback function after the access instance is created.

Declaration of SelfConnectionCallback is:

typedef std::function<void(PresenceStatus status)> SelfConnectionCallback;

and definition of PresenceStatus type is:

typedef enum {
    endpointOnline,     ///< Endpoint is online
    endpointOffline,    ///< Endpoint is offline
} PresenceStatus;
  1. Once the callback is registered to the Access library, connectivity change events will start getting posted to this callback function.
    AccessRet accessRet = access->registerSelfConnectionChangeCallback([self](PresenceStatus status) {
                //
            });

    if (accessRet == OK) {
        //Registered connection change callback function successfully
    } else {
        //Failed to register connection change callback function
    }

The status of SelfConnectionCallback method defines the connectivity status of your device.