lightbulb_outline Please take our October 2018 developer survey. Start survey

ApnSetting.Builder

public static class ApnSetting.Builder
extends Object

java.lang.Object
   ↳ 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:


 // Create an MMS proxy address with a hostname. A network might not be
 // available, so supply a dummy (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();
 

Summary

Public constructors

ApnSetting.Builder()

Default constructor for Builder.

Public methods

ApnSetting build()

Builds ApnSetting from this builder.

ApnSetting.Builder setApnName(String apnName)

Sets the name of the APN.

ApnSetting.Builder setApnTypeBitmask(int apnTypeBitmask)

Sets the bitmask of APN types.

ApnSetting.Builder setAuthType(int authType)

Sets the authentication type of the APN.

ApnSetting.Builder setCarrierEnabled(boolean carrierEnabled)

Sets the current status for this APN.

ApnSetting.Builder setEntryName(String entryName)

Sets a human-readable name that describes the APN.

ApnSetting.Builder setMmsProxyAddress(InetAddress mmsProxy)

Sets the address of an MMS proxy for the APN.

ApnSetting.Builder setMmsProxyPort(int mmsPort)

Sets the MMS proxy port of the APN.

ApnSetting.Builder setMmsc(Uri mmsc)

Sets the MMSC Uri of the APN.

ApnSetting.Builder setMvnoType(int mvnoType)

Sets the MVNO match type for this APN.

ApnSetting.Builder setNetworkTypeBitmask(int networkTypeBitmask)

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

ApnSetting.Builder setOperatorNumeric(String operatorNumeric)

Sets the numeric operator ID for the APN.

ApnSetting.Builder setPassword(String password)

Sets the APN password of the APN.

ApnSetting.Builder setProtocol(int protocol)

Sets the protocol to use to connect to this APN.

ApnSetting.Builder setProxyAddress(InetAddress proxy)

Sets the address of an HTTP proxy for the APN.

ApnSetting.Builder setProxyPort(int port)

Sets the proxy port of the APN.

ApnSetting.Builder setRoamingProtocol(int roamingProtocol)

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

ApnSetting.Builder setUser(String user)

Sets the APN username of the APN.

Inherited methods

Public constructors

ApnSetting.Builder

added in API level 28
public ApnSetting.Builder ()

Default constructor for Builder.

Public methods

build

added in API level 28
public ApnSetting build ()

Builds ApnSetting from this builder.

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

setApnName

added in API level 28
public ApnSetting.Builder setApnName (String apnName)

Sets the name of the APN.

Parameters
apnName String: the name to set for the APN

Returns
ApnSetting.Builder

setApnTypeBitmask

added in API level 28
public ApnSetting.Builder setApnTypeBitmask (int apnTypeBitmask)

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 combination of TYPE_DEFAULT, TYPE_MMS, TYPE_SUPL, TYPE_DUN, TYPE_HIPRI, TYPE_FOTA, TYPE_IMS, TYPE_CBS, TYPE_IA or TYPE_EMERGENCY.

Returns
ApnSetting.Builder

setAuthType

added in API level 28
public ApnSetting.Builder setAuthType (int authType)

Sets the authentication type of the APN.

Parameters
authType int: the authentication type to set for the APN

Value is AUTH_TYPE_NONE, AUTH_TYPE_PAP, AUTH_TYPE_CHAP or AUTH_TYPE_PAP_OR_CHAP.

Returns
ApnSetting.Builder

setCarrierEnabled

added in API level 28
public ApnSetting.Builder setCarrierEnabled (boolean carrierEnabled)

Sets the current status for this APN.

Parameters
carrierEnabled boolean: the current status to set for this APN

Returns
ApnSetting.Builder

setEntryName

added in API level 28
public ApnSetting.Builder setEntryName (String entryName)

Sets a human-readable name that describes the APN.

Parameters
entryName String: the entry name to set for the APN

Returns
ApnSetting.Builder

setMmsProxyAddress

added in API level 28
public ApnSetting.Builder setMmsProxyAddress (InetAddress mmsProxy)

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 InetAddress methods getByName() and getAllByName() require DNS for hostname resolution. To avoid this requirement when setting a hostname, call InetAddress.getByAddress(java.lang.String, byte[]) with both the hostname and a dummy IP address. See above for an example.

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

Returns
ApnSetting.Builder

setMmsProxyPort

added in API level 28
public ApnSetting.Builder setMmsProxyPort (int mmsPort)

Sets the MMS proxy port of the APN.

Parameters
mmsPort int: the MMS proxy port to set for the APN

Returns
ApnSetting.Builder

setMmsc

added in API level 28
public ApnSetting.Builder setMmsc (Uri mmsc)

Sets the MMSC Uri of the APN.

Parameters
mmsc Uri: the MMSC Uri to set for the APN

Returns
ApnSetting.Builder

setMvnoType

added in API level 28
public ApnSetting.Builder setMvnoType (int mvnoType)

Sets the MVNO match type for this APN.

Parameters
mvnoType int: the MVNO match type to set for this APN

Value is MVNO_TYPE_SPN, MVNO_TYPE_IMSI, MVNO_TYPE_GID or MVNO_TYPE_ICCID.

Returns
ApnSetting.Builder

setNetworkTypeBitmask

added in API level 28
public ApnSetting.Builder setNetworkTypeBitmask (int networkTypeBitmask)

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

Parameters
networkTypeBitmask int: the Radio Technology (Network Type) info

Returns
ApnSetting.Builder

setOperatorNumeric

added in API level 28
public ApnSetting.Builder setOperatorNumeric (String operatorNumeric)

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

Parameters
operatorNumeric String: the numeric operator ID to set for this entry

Returns
ApnSetting.Builder

setPassword

added in API level 28
public ApnSetting.Builder setPassword (String password)

Sets the APN password of the APN.

Parameters
password String: the APN password to set for the APN

Returns
ApnSetting.Builder

setProtocol

added in API level 28
public ApnSetting.Builder setProtocol (int protocol)

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 PROTOCOL_IP, PROTOCOL_IPV6, PROTOCOL_IPV4V6 or PROTOCOL_PPP.

Returns
ApnSetting.Builder

setProxyAddress

added in API level 28
public ApnSetting.Builder setProxyAddress (InetAddress proxy)

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 InetAddress methods getAllByName() require DNS for hostname resolution. To avoid this requirement when setting a hostname, call InetAddress.getByAddress(java.lang.String, byte[]) with both the hostname and a dummy IP address. See above for an example.

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

Returns
ApnSetting.Builder

setProxyPort

added in API level 28
public ApnSetting.Builder setProxyPort (int port)

Sets the proxy port of the APN.

Parameters
port int: the proxy port to set for the APN

Returns
ApnSetting.Builder

setRoamingProtocol

added in API level 28
public ApnSetting.Builder setRoamingProtocol (int roamingProtocol)

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 PROTOCOL_IP, PROTOCOL_IPV6, PROTOCOL_IPV4V6 or PROTOCOL_PPP.

Returns
ApnSetting.Builder

setUser

added in API level 28
public ApnSetting.Builder setUser (String user)

Sets the APN username of the APN.

Parameters
user String: the APN username to set for the APN

Returns
ApnSetting.Builder