harmony 鸿蒙VpnExtensionContext

  • 2025-06-12
  • 浏览 (5)

VpnExtensionContext

VpnExtensionContext represents the context of VpnExtensionAbility and is inherited from ExtensionContext.

This module provides the context required for APIs to access the resources of a VpnExtensionAbility object.

NOTE

The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version. The APIs of this module can be used only in the stage model.

Modules to Import

import { VpnExtensionAbility } from '@kit.NetworkKit';

How to Use

You can obtain a VpnExtensionContext object through a VpnExtensionAbility child class instance.

import { VpnExtensionAbility, vpnExtension } from '@kit.NetworkKit';
import { Want } from '@kit.AbilityKit';

export default class MyVpnExtAbility extends VpnExtensionAbility {
  private vpnServerIp: string = 'xxx.xxx.x.x';
  private tunIp: string = 'x.x.x.x';
  private blockedAppName: string = 'xxxx';

  onCreate(want: Want) {
    let VpnConnection: vpnExtension.VpnConnection = vpnExtension.createVpnConnection(this.context);
    console.info("vpn createVpnConnection: " + JSON.stringify(VpnConnection));
  }
}

VpnExtensionAbility

Represents the VPN extension capability.

System capability: SystemCapability.Ability.AbilityRuntime.Core.

Model restriction: This API can be used only in the stage model.

Name Type Mandatory Description
context VpnExtensionContext Yes Specified context.

onCreate

onCreate(want: Want): void

Represents the callback triggered when the extended VPN is initialized.

System capability: SystemCapability.Ability.AbilityRuntime.Core.

Model restriction: This API can be used only in the stage model.

Parameters

Name Type Mandatory Description
want Want Yes Want information.

onDestroy

onDestroy(): void

Represents the callback triggered when the extended VPN is destroyed.

System capability: SystemCapability.Ability.AbilityRuntime.Core.

Model restriction: This API can be used only in the stage model.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Network Kit

harmony 鸿蒙NetConn_ConnectionProperties

harmony 鸿蒙NetConn_HttpProxy

harmony 鸿蒙NetConn_NetAddr

harmony 鸿蒙NetConn_NetCapabilities

harmony 鸿蒙NetConn_NetConnCallback

harmony 鸿蒙NetConn_NetHandle

harmony 鸿蒙NetConn_NetHandleList

harmony 鸿蒙NetConn_NetSpecifier

harmony 鸿蒙NetConn_Route

0  赞