Connection Management

You can create a network connection in your application, and use it to perform various operations. The application can access connection details, such as the IP address, proxy information, gateway information, and connection statistics.

The main features of the Tizen.Network.Connection namespace are:

Prerequisites

To use the Tizen.Network.Connection namespace, the application has to request permission by adding the following privileges to the tizen-manifest.xml file:

XML
Copy
<privileges> <privilege>http://tizen.org/privilege/network.get</privilege> <privilege>http://tizen.org/privilege/network.set</privilege> <privilege>http://tizen.org/privilege/network.profile</privilege> </privileges>

Retrieving Connection Information

To get information about a network connection, use the Tizen.Network.Connection.ConnectionManager class:

  • To retrieve the connection state for a specific connection type (Bluetooth, Ethernet, Ethernet cable, Wi-Fi, or cellular), use the applicable Tizen.Network.Connection.ConnectionManager.XXXState property, for example, Tizen.Network.Connection.ConnectionManager.CellularState. It returns the connection state using the values of the appropriate enumeration (Tizen.Network.Connection.CellularState, Tizen.Network.Connection.ConnectionState, or Tizen.Network.Connection.EthernetCableState):

    C#
    Copy
    CellularState state = ConnectionManager.CellularState; Log.Info(Globals.LogTag, "State = " + state);
  • To retrieve a network address, use the appropriate GetXXX() method, for example, GetIPAddress(). The available method parameter values are defined in the Tizen.Network.Connection.AddressFamily (for retrieving the IPv4 or IPv6 address family) and Tizen.Network.Connection.ConnectionType (for retrieving the MAC address or IPv6 address list) enumerations.

    C#
    Copy
    System.Net.IPAddress ipAddress = ConnectionManager.GetIPAddress(AddressFamily.IPv4); Log.Info(Globals.LogTag, "IpAddress = " + ipAddress.ToString());

Monitoring Connection Changes

You can monitor changes in the IP address, proxy address, Ethernet cable state, and connection type.

To monitor for changes in connection information, such as IP address and connection type:

  1. To receive notifications on specific connection changes, register event handlers using the related XXXChanged events of the Tizen.Network.Connection.ConnectionManager class:

    C#
    Copy
    ConnectionManager.IPAddressChanged += EventHandlerIpAddressChanged; ConnectionManager.ConnectionTypeChanged += EventHandlerConnectionTypeChanged;
  2. Define the event handlers:

    C#
    Copy
    public static void EventHandlerIpAddressChanged(object sender, AddressEventArgs e) { Log.Info(Globals.LogTag, "IPCHANGE = " + e.IPv4Address); } public static void EventHandlerConnectionTypeChanged(object sender, ConnectionTypeEventArgs e) { Log.Info(Globals.LogTag, "ConnectionType = " + e.ConnectionType); }
  3. When the notifications are no longer needed, deregister the event handlers:

    C#
    Copy
    ConnectionManager.IPAddressChanged -= EventHandlerIpAddressChanged; ConnectionManager.ConnectionTypeChanged -= EventHandlerConnectionTypeChanged;

Creating a Cellular Profile

To create a cellular profile, use the CreateCellularProfile() method of the Tizen.Network.Connection.ConnectionManager class:

C#
Copy
CellularProfile rCP = null; string _key = "RequestCellularProfile"; rCP = ConnectionManager.CreateCellularProfile(ConnectionProfileType.Cellular, _key);

Managing Connection Profiles

To change the active connection profile and access connection details:

  • To open a new connection profile:

    1. Retrieve the connection profile you want to open. You can do this in 2 ways:

      • Retrieve a list of all available connection profiles using the GetProfileListAsync() method of the Tizen.Network.Connection.ConnectionProfileManager class, and select the profile you want.

      • Retrieve the connection profile of a specific cellular service.

        Call the GetDefaultCellularProfile() method of the Tizen.Network.Connection.ConnectionProfileManager class and use the appropriate value from the Tizen.Network.Connection.CellularServiceType enumeration as the parameter:

        C#
        Copy
        try { ConnectionProfile currCP = ConnectionProfileManager.GetDefaultCellularProfile(CellularServiceType.Internet); } catch (Exception e) { Log.Info(Globals.LogTag, "Exception = " + e.ToString()); }
    2. Open the connection profile using the ConnectProfileAsync() method of the Tizen.Network.Connection.ConnectionProfileManager class:

      C#
      Copy
      await ConnectionProfileManager.ConnectProfileAsync(currCP);
  • To retrieve the interface name for the active connection profile:

    C#
    Copy
    string name = currCP.InterfaceName; Log.Info(Globals.LogTag, "InterfaceName = " + Name);
  • To retrieve the address information of the active connection profile, use the Tizen.Network.Connection.IAddressInformation instance properties:

    C#
    Copy
    try { var iAddressInformation = currCP.IPv4Settings; } catch (Exception e) { Log.Info(Globals.LogTag, "Exception = " + e.ToString()); } string address = iAddressInformation.Gateway; Log.Info(Globals.LogTag, "GatewayAddress = " + address);

    You can get and set all the IAddressInformation properties: both DNS addresses, gateway and IP addresses, subnet mask, and IP configuration type.

  • Dependencies
    • Tizen 4.0 and Higher
Connectivity and Wireless
Next Network Service Discovery
Submit your feedback to GitHub