Added in API level 28

Builder


open class Builder
kotlin.Any
   ↳ android.telephony.data.ApnSetting.Builder

Provides a convenient way to set the fields of a ApnSetting when creating a new instance. The following settings are required to build an ApnSetting:

  • apnTypeBitmask
  • apnName
  • entryName

The example below shows how you might create a new ApnSetting:

<code>
  // Create an MMS proxy address with a hostname. A network might not be
  // available, so supply a placeholder (0.0.0.0) IPv4 address to avoid DNS lookup.
  String host = "mms.example.com";
  byte[] ipAddress = new byte[4];
  InetAddress mmsProxy;
  try {
    mmsProxy = InetAddress.getByAddress(host, ipAddress);
  } catch (UnknownHostException e) {
    e.printStackTrace();
    return;
  }
 
  ApnSetting apn = new ApnSetting.Builder()
      .setApnTypeBitmask(ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_MMS)
      .setApnName("apn.example.com")
      .setEntryName("Example Carrier APN")
      .setMmsc(Uri.parse("http://mms.example.com:8002"))
      .setMmsProxyAddress(mmsProxy)
      .setMmsProxyPort(8799)
      .build();
  </code>

Summary

Public constructors

Default constructor for Builder.

Public methods
open ApnSetting!

Builds ApnSetting from this builder.

open ApnSetting.Builder
setAlwaysOn(alwaysOn: Boolean)

Sets whether the PDU session brought up by this APN should always be on.

open ApnSetting.Builder
setApnName(apnName: String?)

Sets the name of the APN.

open ApnSetting.Builder
setApnTypeBitmask(apnTypeBitmask: Int)

Sets the bitmask of APN types.

open ApnSetting.Builder
setAuthType(authType: Int)

Sets the authentication type of the APN.

open ApnSetting.Builder
setCarrierEnabled(carrierEnabled: Boolean)

Sets the current status for this APN.

open ApnSetting.Builder
setCarrierId(carrierId: Int)

Sets the carrier id for this APN.

open ApnSetting.Builder
setEntryName(entryName: String?)

Sets a human-readable name that describes the APN.

open ApnSetting.Builder!

Sets the address of an MMS proxy for the APN.

open ApnSetting.Builder

Sets the MMS proxy address of the APN.

open ApnSetting.Builder
setMmsProxyPort(mmsPort: Int)

Sets the MMS proxy port of the APN.

open ApnSetting.Builder
setMmsc(mmsc: Uri?)

Sets the MMSC Uri of the APN.

open ApnSetting.Builder
setMtuV4(mtuV4: Int)

Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv4 routes brought up by this APN setting.

open ApnSetting.Builder
setMtuV6(mtuV6: Int)

Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv6 routes brought up by this APN setting.

open ApnSetting.Builder
setMvnoType(mvnoType: Int)

Sets the MVNO match type for this APN.

open ApnSetting.Builder
setNetworkTypeBitmask(networkTypeBitmask: Int)

Sets Radio Technology (Network Type) info for this APN.

open ApnSetting.Builder
setOperatorNumeric(operatorNumeric: String?)

Sets the numeric operator ID for the APN.

open ApnSetting.Builder
setPassword(password: String?)

Sets the APN password of the APN.

open ApnSetting.Builder
setPersistent(isPersistent: Boolean)

Set if the APN setting should be persistent/non-persistent in modem.

open ApnSetting.Builder
setProfileId(profileId: Int)

Sets the profile id to which the APN saved in modem.

open ApnSetting.Builder
setProtocol(protocol: Int)

Sets the protocol to use to connect to this APN.

open ApnSetting.Builder!

Sets the address of an HTTP proxy for the APN.

open ApnSetting.Builder

Sets the proxy address of the APN.

open ApnSetting.Builder

Sets the proxy port of the APN.

open ApnSetting.Builder
setRoamingProtocol(roamingProtocol: Int)

Sets the protocol to use to connect to this APN when the device is roaming.

open ApnSetting.Builder
setUser(user: String?)

Sets the APN username of the APN.

Public constructors

Builder

Added in API level 28
Builder()

Default constructor for Builder.

Public methods

build

Added in API level 28
open fun build(): ApnSetting!

Builds ApnSetting from this builder.

Return
ApnSetting! null if setApnName(java.lang.String) or setEntryName(java.lang.String) is empty, or setApnTypeBitmask(int) doesn't contain a valid bit, ApnSetting built from this builder otherwise.

setAlwaysOn

Added in API level 35
open fun setAlwaysOn(alwaysOn: Boolean): ApnSetting.Builder

Sets whether the PDU session brought up by this APN should always be on. See 3GPP TS 23.501 section 5.6.13

Parameters
alwaysOn Boolean: the always on status to set for this APN
Return
ApnSetting.Builder This value cannot be null.

setApnName

Added in API level 28
open fun setApnName(apnName: String?): ApnSetting.Builder

Sets the name of the APN.

Parameters
apnName String?: the name to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setApnTypeBitmask

Added in API level 28
open fun setApnTypeBitmask(apnTypeBitmask: Int): ApnSetting.Builder

Sets the bitmask of APN types.

Apn types are usage categories for an APN entry. One APN entry may support multiple APN types, eg, a single APN may service regular internet traffic ("default") as well as MMS-specific connections.

The bitmask of APN types is calculated from APN types defined in ApnSetting.

Parameters
apnTypeBitmask Int: a bitmask describing the types of the APN Value is either 0 or a combination of android.telephony.data.ApnSetting#TYPE_DEFAULT, android.telephony.data.ApnSetting#TYPE_MMS, android.telephony.data.ApnSetting#TYPE_SUPL, android.telephony.data.ApnSetting#TYPE_DUN, android.telephony.data.ApnSetting#TYPE_HIPRI, android.telephony.data.ApnSetting#TYPE_FOTA, android.telephony.data.ApnSetting#TYPE_IMS, android.telephony.data.ApnSetting#TYPE_CBS, android.telephony.data.ApnSetting#TYPE_IA, android.telephony.data.ApnSetting#TYPE_EMERGENCY, android.telephony.data.ApnSetting#TYPE_MCX, android.telephony.data.ApnSetting#TYPE_XCAP, android.telephony.data.ApnSetting#TYPE_BIP, android.telephony.data.ApnSetting#TYPE_VSIM, android.telephony.data.ApnSetting#TYPE_ENTERPRISE, and android.telephony.data.ApnSetting#TYPE_RCS
Return
ApnSetting.Builder This value cannot be null.

setAuthType

Added in API level 28
open fun setAuthType(authType: Int): ApnSetting.Builder

Sets the authentication type of the APN.

Parameters
authType Int: the authentication type to set for the APN Value is android.telephony.data.ApnSetting.AUTH_TYPE_UNKNOWN, android.telephony.data.ApnSetting#AUTH_TYPE_NONE, android.telephony.data.ApnSetting#AUTH_TYPE_PAP, android.telephony.data.ApnSetting#AUTH_TYPE_CHAP, or android.telephony.data.ApnSetting#AUTH_TYPE_PAP_OR_CHAP
Return
ApnSetting.Builder This value cannot be null.

setCarrierEnabled

Added in API level 28
open fun setCarrierEnabled(carrierEnabled: Boolean): ApnSetting.Builder

Sets the current status for this APN.

Parameters
carrierEnabled Boolean: the current status to set for this APN
Return
ApnSetting.Builder This value cannot be null.

setCarrierId

Added in API level 29
open fun setCarrierId(carrierId: Int): ApnSetting.Builder

Sets the carrier id for this APN. See TelephonyManager#getSimCarrierId() which provides more background for what a carrier ID is.

Parameters
carrierId Int: the carrier id to set for this APN
Return
ApnSetting.Builder This value cannot be null.

setEntryName

Added in API level 28
open fun setEntryName(entryName: String?): ApnSetting.Builder

Sets a human-readable name that describes the APN.

Parameters
entryName String?: the entry name to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setMmsProxyAddress

Added in API level 28
Deprecated in API level 29
open fun setMmsProxyAddress(mmsProxy: InetAddress!): ApnSetting.Builder!

Deprecated: use setMmsProxyAddress(java.lang.String) instead.

Sets the address of an MMS proxy for the APN. The MMS proxy address can be an IP address or hostname. If mmsProxy contains both an IP address and hostname, this method ignores the IP address.

The java.net.InetAddress methods getByName() and getAllByName() require DNS for hostname resolution. To avoid this requirement when setting a hostname, call java.net.InetAddress#getByAddress(java.lang.String, byte[]) with both the hostname and a placeholder IP address. See above for an example.

Parameters
mmsProxy InetAddress!: the MMS proxy address to set for the APN

setMmsProxyAddress

Added in API level 29
open fun setMmsProxyAddress(mmsProxy: String?): ApnSetting.Builder

Sets the MMS proxy address of the APN.

Parameters
mmsProxy String?: the MMS proxy address to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setMmsProxyPort

Added in API level 28
open fun setMmsProxyPort(mmsPort: Int): ApnSetting.Builder

Sets the MMS proxy port of the APN.

Parameters
mmsPort Int: the MMS proxy port to set for the APN
Return
ApnSetting.Builder This value cannot be null.

setMmsc

Added in API level 28
open fun setMmsc(mmsc: Uri?): ApnSetting.Builder

Sets the MMSC Uri of the APN.

Parameters
mmsc Uri?: the MMSC Uri to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setMtuV4

Added in API level 33
open fun setMtuV4(mtuV4: Int): ApnSetting.Builder

Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv4 routes brought up by this APN setting. Note this value will only be used when MTU size is not provided in DataCallResponse#getMtuV4() during network bring up.

Parameters
mtuV4 Int: the MTU size in bytes of the route.
Return
ApnSetting.Builder This value cannot be null.

setMtuV6

Added in API level 33
open fun setMtuV6(mtuV6: Int): ApnSetting.Builder

Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv6 routes brought up by this APN setting. Note this value will only be used when MTU size is not provided in DataCallResponse#getMtuV6() during network bring up.

Parameters
mtuV6 Int: the MTU size in bytes of the route.
Return
ApnSetting.Builder This value cannot be null.

setMvnoType

Added in API level 28
open fun setMvnoType(mvnoType: Int): ApnSetting.Builder

Sets the MVNO match type for this APN.

Parameters
mvnoType Int: the MVNO match type to set for this APN Value is android.telephony.data.ApnSetting.MVNO_TYPE_UNKNOWN, android.telephony.data.ApnSetting#MVNO_TYPE_SPN, android.telephony.data.ApnSetting#MVNO_TYPE_IMSI, android.telephony.data.ApnSetting#MVNO_TYPE_GID, or android.telephony.data.ApnSetting#MVNO_TYPE_ICCID
Return
ApnSetting.Builder This value cannot be null.

setNetworkTypeBitmask

Added in API level 28
open fun setNetworkTypeBitmask(networkTypeBitmask: Int): ApnSetting.Builder

Sets Radio Technology (Network Type) info for this APN.

Parameters
networkTypeBitmask Int: the Radio Technology (Network Type) info
Return
ApnSetting.Builder This value cannot be null.

setOperatorNumeric

Added in API level 28
open fun setOperatorNumeric(operatorNumeric: String?): ApnSetting.Builder

Sets the numeric operator ID for the APN. Numeric operator ID is defined as android.provider.Telephony.Carriers#MCC + android.provider.Telephony.Carriers#MNC.

Parameters
operatorNumeric String?: the numeric operator ID to set for this entry This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setPassword

Added in API level 28
open fun setPassword(password: String?): ApnSetting.Builder

Sets the APN password of the APN.

Parameters
password String?: the APN password to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setPersistent

Added in API level 33
open fun setPersistent(isPersistent: Boolean): ApnSetting.Builder

Set if the APN setting should be persistent/non-persistent in modem.

Parameters
isPersistent Boolean: true if this APN setting should be persistent/non-persistent in modem.
Return
ApnSetting.Builder The same instance of the builder. This value cannot be null.

setProfileId

Added in API level 33
open fun setProfileId(profileId: Int): ApnSetting.Builder

Sets the profile id to which the APN saved in modem.

Parameters
profileId Int: the profile id to set for the APN.
Return
ApnSetting.Builder This value cannot be null.

setProtocol

Added in API level 28
open fun setProtocol(protocol: Int): ApnSetting.Builder

Sets the protocol to use to connect to this APN.

Protocol is one of the PDP_type values in TS 27.007 section 10.1.1.

Parameters
protocol Int: the protocol to set to use to connect to this APN Value is android.telephony.data.ApnSetting#PROTOCOL_IP, android.telephony.data.ApnSetting#PROTOCOL_IPV6, android.telephony.data.ApnSetting#PROTOCOL_IPV4V6, android.telephony.data.ApnSetting#PROTOCOL_PPP, android.telephony.data.ApnSetting#PROTOCOL_NON_IP, or android.telephony.data.ApnSetting#PROTOCOL_UNSTRUCTURED
Return
ApnSetting.Builder This value cannot be null.

setProxyAddress

Added in API level 28
Deprecated in API level 29
open fun setProxyAddress(proxy: InetAddress!): ApnSetting.Builder!

Deprecated: use setProxyAddress(java.lang.String) instead.

Sets the address of an HTTP proxy for the APN. The proxy address can be an IP address or hostname. If proxy contains both an IP address and hostname, this method ignores the IP address.

The java.net.InetAddress methods getAllByName() require DNS for hostname resolution. To avoid this requirement when setting a hostname, call java.net.InetAddress#getByAddress(java.lang.String, byte[]) with both the hostname and a placeholder IP address. See above for an example.

Parameters
proxy InetAddress!: the proxy address to set for the APN

setProxyAddress

Added in API level 29
open fun setProxyAddress(proxy: String?): ApnSetting.Builder

Sets the proxy address of the APN.

Parameters
proxy String?: the proxy address to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.

setProxyPort

Added in API level 28
open fun setProxyPort(port: Int): ApnSetting.Builder

Sets the proxy port of the APN.

Parameters
port Int: the proxy port to set for the APN
Return
ApnSetting.Builder This value cannot be null.

setRoamingProtocol

Added in API level 28
open fun setRoamingProtocol(roamingProtocol: Int): ApnSetting.Builder

Sets the protocol to use to connect to this APN when the device is roaming.

Roaming protocol is one of the PDP_type values in TS 27.007 section 10.1.1.

Parameters
roamingProtocol Int: the protocol to set to use to connect to this APN when roaming Value is android.telephony.data.ApnSetting#PROTOCOL_IP, android.telephony.data.ApnSetting#PROTOCOL_IPV6, android.telephony.data.ApnSetting#PROTOCOL_IPV4V6, android.telephony.data.ApnSetting#PROTOCOL_PPP, android.telephony.data.ApnSetting#PROTOCOL_NON_IP, or android.telephony.data.ApnSetting#PROTOCOL_UNSTRUCTURED
Return
ApnSetting.Builder This value cannot be null.

setUser

Added in API level 28
open fun setUser(user: String?): ApnSetting.Builder

Sets the APN username of the APN.

Parameters
user String?: the APN username to set for the APN This value may be null.
Return
ApnSetting.Builder This value cannot be null.