Starting from version 6.0.2(22), this kit supports listening to the multi-network concurrency status.
Your app can listen to the multi-network concurrency status to detect any changes on available network paths and select an appropriate strategy for transmitting data through them.
For details about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| int32_t HMS_NetworkBoost_RegisterMultiPathStateChangeCallback(HMS_NetworkBoost_OnMultiPathStateChangecallback, uint32_t *callbackId) | Registers the callback for multi-network concurrency status changes. |
| int32_t HMS_NetworkBoost_UnregisterMultiPathStateChangeCallback(uint32_t callbackId) | Deregisters the callback for multi-network concurrency status changes. |
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
Call the HMS_NetworkBoost_RegisterMultiPathStateChangeCallback API to obtain multi-network concurrency status changes.
uint32_t callbackId = 0;
void onMultiPathStateChangeCallback(NetworkBoost_MultiPathStateChange* result)
{
// Callback for multi-network concurrency status changes.
if (result != NULL) {
printf("Multi-network status callback: multi-network status = %d, multi-network status change cause = %d\n", result->multiPathState, result->changeCause);
printf("Multi-network status callback: multi-link netHandle = %d, multi-link status = %d\n", result->netHandle, result->pathState);
printf("Multi-network status callback: multi-link type = %d\n", result->pathType);
} else {
printf("Callback parameters are empty.\n");
}
}
int32_t RegisterMultiPathStateChange()
{
// 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_RegisterMultiPathStateChangeCallback(onMultiPathStateChangeCallback, &callbackId);
printf("Result of registering the callback for multi-network concurrency status changes: %d, Id: %d\n", ret, callbackId);
return ret;
} Deregister the callback for multi-network concurrency status changes after your app process ends.
int32_t UnregisterMultiPathStateChange() {
// Deregister the callback using the callback ID obtained during registration.
int32_t ret = HMS_NetworkBoost_UnregisterMultiPathStateChangeCallback(callbackId);
printf("Result of deregistering the callback for multi-network concurrency status changes: %d\n", ret);
return ret;
}