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
- To get connectivity change events, call
enableConnectivityChangeNotification()
method fromAccess
class once after theAccess
build is finished.AnyConnectApi.get().getAccess().enableConnectivityChangeNotification();
- Next, attach interface
Access.ConnectivityChangeListener
to Access by callingRegisterConnectivityListener(ConnectivityChangeListener listener)
method.AnyConnectApi.get().getAccess().RegisterConnectivityListener(connectivityChangeListener);
- Once the interface is registered to the
Access
library, connectivity change events will start getting posted to theonConnectivityChange(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
ofonConnectivityChange
method defines the connectivity status of your device.
iOS
- To get connectivity change events, call
registerSelfConnectionChangeCallback(SelfConnectionCallback callback)
method of theAccess
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;
- 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
ofSelfConnectionCallback
method defines the connectivity status of your device.
Updated over 2 years ago