public class CellularNetwork
extends java.lang.Object
Typically, to be aware of current information about CellularNetworks,
an application will not retain references to CellularNetworks instances
and will use the CellularNetworkListener
,
getAvailableNetworks()
, or getRegisteredNetworks()
to get current information.
Access points corresponding to CellularNetworks are provided by the Generic Connection Framework AccessPoint API. The AccessPoint will have the same name and network type as the CellularNetwork.
Properties available viagetProperties()
:
Property | Description | Value | Network Type |
---|---|---|---|
mcc | MCC (Mobile Country Code) number of the network | MCC number | 3GPP, CDMA |
mnc | MNC (Mobile Network Code) number of the network | MNC number | 3GPP, CDMA |
sid | SID (System Identifier) number of the network | SID number | CDMA |
nid | NID (Network Identifier) number of the network | NID number | CDMA |
Cell properties available via getCellProperties()
:
Property | Description | Value | Network Type |
---|---|---|---|
lac | LAC (Location Area Code) number of the current cell | LAC number | 3GPP |
cid | CID (Cell Identifier) number of the current cell | CID number | 3GPP |
bid | BID (Base Station Identifier) number of the current cell | BID number | CDMA |
See the following example:
.
// Locate the CellularNetwork for the desired phone number
// And use the corresponding AccessPoint to open a connection
String phoneNumber = "+19999999999";
for (CellularNetwork cn : CellularNetwork.getRegisteredNetworks()) {
Subscriber subscriber = cn.getSubscriber();
if (subscriber != null && subscriber.getPhoneNumber().equals(phoneNumber)) {
// The corresponding AccessPoint has the same name
AccessPoint ap = AccessPoint.of(cn.getName());
...
// See the AccessPoint Example for use with Connector.open
ConnectionOption<String> accessPointOption =
new ConnectionOption<String>("AccessPoint", cn.getName());
// Open the connection using the specific AccessPoint
Connection c = Connector.open("http://www.oracle.com/index.html", accessPointOption); }
}
// Subscriber not registered to the network
See the description of javax.microedition.io.Connector
for more details.
Modifier and Type | Field and Description |
---|---|
static int |
NETWORK_AVAILABLE
Network available status value;
|
static int |
NETWORK_FORBIDDEN
Network FORBIDDEN status value;
|
static int |
NETWORK_LIMITED
Network Limited status value;
|
static int |
NETWORK_REGISTERED
Network registered status value;
|
static int |
NETWORK_UNKNOWN
Network Unknown status value;
|
Modifier and Type | Method and Description |
---|---|
static void |
addListener(CellularNetworkListener listener)
Adds listener to receive cellular networks related events.
|
boolean |
deRegister()
Unregister from the CellularNetwork.
|
static CellularNetwork[] |
getAvailableNetworks()
Returns cellular networks available to the device.
|
static CellularNetwork |
getByName(java.lang.String networkName)
Returns the CellularNetwork by name.
|
java.util.Map<java.lang.String,java.lang.String> |
getCellProperties()
Returns a map containing current cell identifiers.
|
java.lang.String |
getName()
Returns the network name.
|
java.lang.String |
getNetworkType()
Returns the network type.
|
java.util.Map<java.lang.String,java.lang.String> |
getProperties()
Returns a map containing network properties, such as
operator and network identifiers.
|
static CellularNetwork[] |
getRegisteredNetworks()
Returns cellular networks to which the device is registered.
|
int |
getSignalStrength()
Returns the current signal strength.
|
int |
getStatus()
Returns the current status of the CellularNetwork.
|
Subscriber |
getSubscriber()
Returns the Subscriber for the network.
|
boolean |
isRoaming()
Indicates whether the subscriber registered to this network is
considered to be roaming.
|
void |
register(Subscriber subscriber)
Register to the CellularNetwork using the subscriber.
|
static void |
removeListener(CellularNetworkListener listener)
Removes previously added listener.
|
public static final int NETWORK_REGISTERED
public static final int NETWORK_AVAILABLE
public static final int NETWORK_UNKNOWN
public static final int NETWORK_FORBIDDEN
public static final int NETWORK_LIMITED
public static CellularNetwork[] getRegisteredNetworks()
getAvailableNetworks()
public static CellularNetwork[] getAvailableNetworks()
getRegisteredNetworks()
public static CellularNetwork getByName(java.lang.String networkName)
networkName
- the network name to returnnull
is returned if no CellularNetwork with the namepublic int getStatus()
NETWORK_REGISTERED
, NETWORK_AVAILABLE
,
NETWORK_UNKNOWN
, NETWORK_FORBIDDEN
or
NETWORK_LIMITED
public void register(Subscriber subscriber) throws java.io.IOException
Invoking #register
with a null
Subscriber will
enable automatic registration mode in which the device can register
to any network using any of the available Subscriber.getSubscribers()
.
If the device is already registered, the current registration must be maintained.
When and if registration is successful a CellularNetworkListener.NETWORK_CONNECTED
event will be delivered to the listeners.
subscriber
- the Subscriber to register;
if subscriber
is null
then automatic registration
mode is enabledjava.io.IOException
- if the Registration does not succeed.java.lang.IllegalStateException
- if the CellularNetwork was explicitly
registered to a different Subscriber and the new subscriber is
not null
java.lang.SecurityException
- if the CellularPermission for "networks" is not grantedpublic boolean deRegister()
#deRegister
the device
will not automatically register again.
When and if de-registration is successful a CellularNetworkListener.NETWORK_DISCONNECTED
event will be delivered to the listeners.
true
if it was previously registered and
de-registration occurred; false
otherwisejava.lang.SecurityException
- if the CellularPermission for "networks" is not grantedregister(javax.microedition.cellular.Subscriber)
public static void addListener(CellularNetworkListener listener)
As soon as a listener is added it will be notified about all currently connected networks. For example, notifyNetworkEvent with NETWORK_CONNECTED event will be called for each registered network. This prevents a race condition that could exist between registering listener and registering to the network.
Does nothing if the listener is already registered as a cellular network listener.
listener
- the listener to addjava.lang.NullPointerException
- if the listener is nullpublic static void removeListener(CellularNetworkListener listener)
Does nothing if the listener is not registered as a cellular network listener.
listener
- the listener to removejava.lang.NullPointerException
- if the listener is nullpublic java.lang.String getNetworkType()
The network type should be one of:
"IS-95"
, "1xRTT"
, "EVDO"
, "GPRS"
,
"EDGE"
, "UTRAN"
, "HSDPA"
, "HSDPA/HSUDA"
,
or "LTE"
.
public Subscriber getSubscriber()
null
is returned if the Network is not registered to a subscribergetStatus()
public java.lang.String getName() throws java.lang.SecurityException
The network name is retrieved while registering the device with the network and does not change.
java.lang.SecurityException
- if the Security policy does not permit
CellularPermission with name "network".public boolean isRoaming() throws NetworkDisconnectedException
NetworkDisconnectedException
- if device was disconnected from this
networkpublic int getSignalStrength() throws NetworkDisconnectedException
NetworkDisconnectedException
- if device was disconnected from this
networkpublic java.util.Map<java.lang.String,java.lang.String> getProperties()
The keys are defined in the Cellular Network Properties Table.
The values are only available if the getNetworkType()
value
is listed for the key.
The value null
is returned from Map.get(key)
if the key is not defined for the network type.
String values that represent numbers are decimal unless otherwise noted.
java.lang.SecurityException
- if the Security policy does not permit
CellularPermission with name "network".public java.util.Map<java.lang.String,java.lang.String> getCellProperties() throws NetworkDisconnectedException
The keys are defined in the Cell Properties Table.
The values are only available if the getNetworkType()
is listed for the key.
The value null
is returned from Map.get(key)
if the key is not defined for the network type.
String values that represent numbers are decimal unless otherwise noted.
java.lang.SecurityException
- if the Security policy does not permit
CellularPermission with name "network".NetworkDisconnectedException
- if device was disconnected from this
networkCopyright (c) 2013, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.