目录

Listening to Multi-Network Concurrency Suggestions

Use Case

When the device detects that an app may need to use multi-network concurrency for network acceleration in specific scenarios such as weak signal and network handover, it provides relevant suggestions. Your app can listen to these suggestions and decide whether to initiate a multi-network concurrency request.

API Description

For details about the APIs, please refer to API Reference.

API Description
on(type: 'multiPathRecommendation', callback: Callback<MultiPathRecommendationInfo>): void Subscribes to multi-network concurrency suggestion changes.
off(type: 'multiPathRecommendation', callback?: Callback<MultiPathRecommendationInfo>): void Unsubscribes from multi-network concurrency suggestion changes.

Development Procedure

  1. Import the Network Boost Kit module.

    import { netHandover } from '@kit.NetworkBoostKit';
    import { BusinessError } from '@kit.BasicServicesKit';
  2. Subscribe to multi-network concurrency suggestion changes.

    try {
      netHandover.on('multiPathRecommendation', (data: netHandover.MultiPathRecommendationInfo) => {
        // Callback information processing.
        console.info("on multiPathRecommendation: " + JSON.stringify(data));
      });
    } catch (err) {
      console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
    }
  3. Unsubscribe from multi-network concurrency suggestion changes after your app process ends.

    try {
      netHandover.off('multiPathRecommendation');
    } catch (err) {
      console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
    }