When the network signal is weak and the device initiates a network handover (such as between Wi-Fi and cellular networks or between primary and secondary SIM cards), the device will notify your app upon the start and end of the handover. Then, your app can re-establish the link accordingly and swiftly restore services, providing smooth, fast, and low-latency network experience.
For details about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| int32_t HMS_NetworkBoost_RegisterHandoverChangeCallback(HMS_NetworkBoost_HandoverCallback* callback, uint32_t* callbackId) | Registers the network handover callback. |
| int32_t HMS_NetworkBoost_UnregisterHandoverChangeCallback(uint32_t callbackId) | Deregisters the network handover callback. |
Import the Network Boost Kit module.
#include "NetworkBoostKit/network_boost_handover.h" #include <cstdio>
Add the following library to the CMakeLists.txt file. For details, please refer to Preparations for C API Development.
libnetwork_boost.so
Register the network handover callback.
uint32_t callbackId = 0;
void onNetworkHandoverStart(NetworkBoost_HandoverStart* handoverStart)
{
// Callback for the start of network handover. Adjust the data transmission policy based on the suggestion in HandoverStart.
}
void onNetworkHandoverComplete(NetworkBoost_HandoverComplete* handoverComplete)
{
// Callback for the end of network handover. Adjust the network speed and re-establish the link based on the suggestion in HandoverComplete.
}
int32_t RegisterNetworkHandoverCallback()
{
HMS_NetworkBoost_HandoverCallback callback;
callback.onNetworkHandoverStart = onNetworkHandoverStart;
callback.onNetworkHandoverComplete = onNetworkHandoverComplete;
// Register a callback and obtain the callback ID. The ID is returned by the system and will be used for subsequent deregistration.
int32_t ret = HMS_NetworkBoost_RegisterHandoverChangeCallback(&callback, &callbackId);
printf("Network handover callback registration result: %d, Id:%d\n", ret, callbackId);
return ret;
} Deregister the network handover callback after your app process ends.
int32_t UnregisterNetworkHandoverCallback() {
// Deregister the callback using the callback ID obtained during registration.
int32_t ret = HMS_NetworkBoost_UnregisterHandoverChangeCallback(callbackId);
printf("Network handover callback deregistration result: %d\n", ret);
return ret;
}