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 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();
Summary
Public constructors | |
---|---|
Builder()
Default constructor for Builder. |
Public methods | |
---|---|
ApnSetting
|
build()
Builds |
ApnSetting.Builder
|
setAlwaysOn(boolean alwaysOn)
Sets whether the PDU session brought up by this APN should always be on. |
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
|
setCarrierId(int carrierId)
Sets the carrier id for this APN. |
ApnSetting.Builder
|
setEntryName(String entryName)
Sets a human-readable name that describes the APN. |
ApnSetting.Builder
|
setMmsProxyAddress(InetAddress mmsProxy)
This method was deprecated
in API level 29.
use |
ApnSetting.Builder
|
setMmsProxyAddress(String mmsProxy)
Sets the MMS proxy address of 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
|
setMtuV4(int mtuV4)
Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv4 routes brought up by this APN setting. |
ApnSetting.Builder
|
setMtuV6(int mtuV6)
Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv6 routes brought up by this APN setting. |
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
|
setPersistent(boolean isPersistent)
Set if the APN setting should be persistent/non-persistent in modem. |
ApnSetting.Builder
|
setProfileId(int profileId)
Sets the profile id to which the APN saved in modem. |
ApnSetting.Builder
|
setProtocol(int protocol)
Sets the protocol to use to connect to this APN. |
ApnSetting.Builder
|
setProxyAddress(InetAddress proxy)
This method was deprecated
in API level 29.
use |
ApnSetting.Builder
|
setProxyAddress(String proxy)
Sets the proxy address of 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
Public methods
build
public ApnSetting build ()
Builds ApnSetting
from this builder.
Returns | |
---|---|
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
public ApnSetting.Builder setAlwaysOn (boolean alwaysOn)
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 |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setApnName
public ApnSetting.Builder setApnName (String apnName)
Sets the name of the APN.
Parameters | |
---|---|
apnName |
String : the name to set for the APN
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setApnTypeBitmask
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 a combination of ApnSetting.TYPE_DEFAULT , ApnSetting.TYPE_MMS , ApnSetting.TYPE_SUPL , ApnSetting.TYPE_DUN , ApnSetting.TYPE_HIPRI , ApnSetting.TYPE_FOTA , ApnSetting.TYPE_IMS , ApnSetting.TYPE_CBS , ApnSetting.TYPE_IA , ApnSetting.TYPE_EMERGENCY , ApnSetting.TYPE_MCX , ApnSetting.TYPE_XCAP , ApnSetting.TYPE_BIP , ApnSetting.TYPE_VSIM , ApnSetting.TYPE_ENTERPRISE , ApnSetting.TYPE_RCS , ApnSetting.TYPE_OEM_PAID , and ApnSetting.TYPE_OEM_PRIVATE |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setAuthType
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 android.telephony.data.ApnSetting.AUTH_TYPE_UNKNOWN, ApnSetting.AUTH_TYPE_NONE , ApnSetting.AUTH_TYPE_PAP , ApnSetting.AUTH_TYPE_CHAP , or ApnSetting.AUTH_TYPE_PAP_OR_CHAP |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setCarrierEnabled
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 |
This value cannot be null . |
setCarrierId
public ApnSetting.Builder setCarrierId (int carrierId)
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 |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setEntryName
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
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setMmsProxyAddress
public ApnSetting.Builder setMmsProxyAddress (InetAddress mmsProxy)
This method was deprecated
in API level 29.
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 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 placeholder IP address. See above
for an
example.
Parameters | |
---|---|
mmsProxy |
InetAddress : the MMS proxy address to set for the APN |
Returns | |
---|---|
ApnSetting.Builder |
setMmsProxyAddress
public ApnSetting.Builder setMmsProxyAddress (String mmsProxy)
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 . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setMmsProxyPort
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 |
This value cannot be null . |
setMmsc
public ApnSetting.Builder setMmsc (Uri mmsc)
Sets the MMSC Uri of the APN.
Parameters | |
---|---|
mmsc |
Uri : the MMSC Uri to set for the APN
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setMtuV4
public ApnSetting.Builder setMtuV4 (int mtuV4)
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. |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setMtuV6
public ApnSetting.Builder setMtuV6 (int mtuV6)
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. |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setMvnoType
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 android.telephony.data.ApnSetting.MVNO_TYPE_UNKNOWN, ApnSetting.MVNO_TYPE_SPN , ApnSetting.MVNO_TYPE_IMSI , ApnSetting.MVNO_TYPE_GID , or ApnSetting.MVNO_TYPE_ICCID |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setNetworkTypeBitmask
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 |
This value cannot be null . |
setOperatorNumeric
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
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setPassword
public ApnSetting.Builder setPassword (String password)
Sets the APN password of the APN.
Parameters | |
---|---|
password |
String : the APN password to set for the APN
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
See also:
setPersistent
public ApnSetting.Builder setPersistent (boolean isPersistent)
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. |
Returns | |
---|---|
ApnSetting.Builder |
The same instance of the builder.
This value cannot be null . |
setProfileId
public ApnSetting.Builder setProfileId (int profileId)
Sets the profile id to which the APN saved in modem.
Parameters | |
---|---|
profileId |
int : the profile id to set for the APN. |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setProtocol
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 ApnSetting.PROTOCOL_IP , ApnSetting.PROTOCOL_IPV6 , ApnSetting.PROTOCOL_IPV4V6 , ApnSetting.PROTOCOL_PPP , ApnSetting.PROTOCOL_NON_IP , or ApnSetting.PROTOCOL_UNSTRUCTURED |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setProxyAddress
public ApnSetting.Builder setProxyAddress (InetAddress proxy)
This method was deprecated
in API level 29.
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 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 placeholder IP address. See above
for an
example.
Parameters | |
---|---|
proxy |
InetAddress : the proxy address to set for the APN |
Returns | |
---|---|
ApnSetting.Builder |
setProxyAddress
public ApnSetting.Builder setProxyAddress (String proxy)
Sets the proxy address of the APN.
Parameters | |
---|---|
proxy |
String : the proxy address to set for the APN
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setProxyPort
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 |
This value cannot be null . |
setRoamingProtocol
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 ApnSetting.PROTOCOL_IP , ApnSetting.PROTOCOL_IPV6 , ApnSetting.PROTOCOL_IPV4V6 , ApnSetting.PROTOCOL_PPP , ApnSetting.PROTOCOL_NON_IP , or ApnSetting.PROTOCOL_UNSTRUCTURED |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |
setUser
public ApnSetting.Builder setUser (String user)
Sets the APN username of the APN.
Parameters | |
---|---|
user |
String : the APN username to set for the APN
This value may be null . |
Returns | |
---|---|
ApnSetting.Builder |
This value cannot be null . |