Back to top

Access Point Name

An Access Point Name (APN) defines a gateway between a mobile network and the Internet. Mobile devices use this gateway to access the Internet through a mobile carrier network. Mobile carriers define the settings needed for devices to connect through their gateway.

With the Knox SDK, you can manage APNs on a mobile device. Specifically, you can:

  • create an APN
  • update an APN’s settings
  • get a list of APNs created
  • get the settings for an APN
  • set a preferred or default APN
  • get the preferred APN’s settings
  • delete an APN

You can configure these APN settings:

  • name
  • user-friendly name
  • proxy
  • port number
  • user name
  • user password
  • server address
  • MMS server address (MMSC)
  • MMS proxy address
  • MMS port number
  • Mobile Country Code (MCC)
  • Mobile Network Code (MNC)
  • authentication type — none, PAP, CHAP, or PAP or CHAP
  • APN type — default (APN used for all data), MMS (for MMS data), supl (for Secure User Plane Location)
  • APN protocol — IPv4, IPv6, or IPv4 or v6
  • roaming protocol — IPv4, IPv6, or IPv4 or v6
  • unique ID
  • Mobile Virtual Network Operator (MVNO)

Use the following Knox SDK classes:

Create an APN

To create an APN on a mobile device, do the following:

  1. Create an enterprise device manager.
  2. Create an APN policy.
  3. Configure APN settings.
  4. Create the APN.

The sample code below shows how to set up an APN for T-Mobile:

// create a device manager, create an APN policy, and APN settings object
EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();
ApnSettings apnSettings = new ApnSettings();
// configure the APN settings for T-Mobile
apnSettings.apn = "fast.t-mobile.com";
apnSettings.name = "T-Mobile US LTE";
apnSettings.user = "ApnUser";
apnSettings.password = "1234";
apnSettings.mmsc = "http://mms.msg.eng.t-mobile.com/mms/wapenc";
apnSettings.mmsProxy = "127.0.0.0";
apnSettings.mmsPort = "80";
apnSettings.mcc = "310";
apnSettings.mnc = "260";
apnSettings.type = "default";
// create the APN
apnSettingsPolicy.createApnSettings(apnSettings);

For additional code snippets showing how to update, list, get, or delete APNs, see ApnSettingsPolicy.

Configure a Mobile Virtual Network Operator

Starting from Android 9.0 (Pie), some carriers or SIM cards need the Mobile Virtual Network Operator (MVNO) to be configured.

An MVNO is a mobile device reseller that uses another carrier’s mobile network. An example is Consumer Cellular, whose devices use the mobile networks of AT&T and T-Mobile.

You can set up multiple APN configurations on a device in these use cases:

  • To support different MVNOs that access the same network.
  • To set up different subscriber accounts within the same network or reseller. For example, you could switch to a SIM card for a different subscriber or reseller but on the same mobile network.

With Knox v3.4, you can now configure these MVNO settings in ApnSettings:

  • mvno_type — Set to one of the following:

    • None (empty string): This is the usual setting, and means that this APN configuration is not restricted for use on a particular MVNO or subscriber account. When the type is set to None, the value field is not used.
    • MVNO_SPN: Indicates that the value is a Service Provider Name.
    • MVNO_IMSI: Indicates that the value is an International Mobile Subscriber Identity. This value is unique to every subscriber account on any network worldwide.
    • MVNO_GID: Indicates that the value is a Group Identifier, level 1.
  • mvno_value — Set to a value that identifies the MVNO using the specified type.

Together, the mvno_type and mvno_value fields allow an APN configuration to be restricted for use only when using particular MVNOs or subscriber accounts.

Without this setting, custom-defined APN configurations are selected according to Mobile Country Code (MCC) and Mobile Network Code (MNC) only, which specifies the mobile network the device subscribes to but not the particular retailer or reseller, or account on a network.

The sample code below shows how to set up MVNO for Consumer Cellular:

// configure MVNO settings for Consumer Cellular
apnSettings.mvno_type = ApnSettings.MVNO_IMSI;
apnSettings.mvno_value = "3104101";

Configure MVNO on older devices

Devices that are running Android P and Knox v3.3 or v3.2.1 can use reflection to set the MVNO fields in ApnSettings. To set up MVNO in devices running these Knox releases, use reflection.

To get APN field settings using reflection:

// for Android P devices with Knox 3.2.1 or 3.3, get mvo_type and mvo_value via reflection
ApnSettings apnSettings = new ApnSettings();
int knoxApiLevel = EnterpriseDeviceManager.getAPILevel();

if (knoxApiLevel == EnterpriseDeviceManager.KNOX_VERSION_CODES.KNOX_3_2_1 ||
    knoxApiLevel == EnterpriseDeviceManager.KNOX_VERSION_CODES.KNOX_3_3) {
    Class apnSettingsClass = ApnSettings.class;
    try {
        Field mvno_type_field = apnSettingsClass.getField("mvno_type");
        String apnSettings_mvno_type = (String) mvno_type_field.get(apnSettings);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    try {
        Field mvno_value_field = apnSettingsClass.getField("mvno_value");
        String apnSettings_mvno_value = (String) mvno_value_field.get(apnSettings);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

To set APN field settings using reflection:

// for Android P devices with Knox 3.2.1 or 3.3, set mvo_type and mvo_value via reflection
ApnSettings apnSettings = new ApnSettings();
int knoxApiLevel = EnterpriseDeviceManager.getAPILevel();

if (knoxApiLevel == EnterpriseDeviceManager.KNOX_VERSION_CODES.KNOX_3_2_1 ||
    knoxApiLevel == EnterpriseDeviceManager.KNOX_VERSION_CODES.KNOX_3_3) {
    Class apnSettingsClass = ApnSettings.class;
    try {
        Field mvno_type_field = apnSettingsClass.getField("mvno_type");

        // for example: configure MVNO settings for Consumer Cellular
        mvno_type_field.set(apnSettings, ApnSettings.MVNO_IMSI);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    try {
        Field mvno_value_field = apnSettingsClass.getField("mvno_value");
        // for example: configure MVNO settings for Consumer Cellular
        mvno_value_field.set(apnSettings, "3104101");
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

Is this page helpful?