public class CellularNetwork
extends java.lang.Object
registered
to the cellular network.
When registered, the device provides a javax.microedition.io.NetworkInterface
for each registered CellularNetwork.
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.
getProperties()
:
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 |
protocol | For network type 3GPP, one of "GPRS" , "EDGE" ,
"UTRAN" , "HSDPA" , "HSDPA/HSUDA" ,
or "LTE"
For network type CDMA, one of |
Data Protocol | 3GPP, 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 |
.
// Locate the CellularNetwork for the desired phone number
// And use a 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)) {
NetworkInterface ni = cn.getNetworkInterface();
AccessPoint[] accessPoints = ni.getConnectedAccessPoints();
if (accessPoints.length >= 1) {
// See the AccessPoint Example for use with Connector.open
ConnectionOption<AccessPoint> accessPointOption =
new ConnectionOption<>("AccessPoint", accessPoints[0]);
// Open the connection using the specific AccessPoint
try (Connection c = Connector.open("http://www.oracle.com/index.html", accessPointOption)) {
// Use the connection
} catch (IOException ioe) {
return false;
}
}
}
}
// 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.
|
static CellularNetwork |
getByNetworkInterface(javax.microedition.io.NetworkInterface ni)
Returns the CellularNetwork for a NetworkInterface.
|
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.
|
javax.microedition.io.NetworkInterface |
getNetworkInterface()
Returns the
NetworkInterface connecting this CellularNetwork. |
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.
|
java.lang.String |
getType()
Returns the network type of this CellularNetwork.
|
boolean |
isRoaming()
Indicates whether the subscriber registered to this network is
considered to be roaming.
|
CellularNetwork |
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)
getAvailableNetworks
;
One of the CellularNetworks with a matching name is returned;
the choice is arbitrary if more than one has the same name.networkName
- the network name to returnnull
is returned if no CellularNetwork has the namepublic static CellularNetwork getByNetworkInterface(javax.microedition.io.NetworkInterface ni)
getNetworkInterface()
is equal to the requested
NetworkInterface.ni
- the NetworkInterfaceni
;
null
is returned if no CellularNetwork matchespublic int getStatus()
NETWORK_REGISTERED
, NETWORK_AVAILABLE
,
NETWORK_UNKNOWN
, NETWORK_FORBIDDEN
or
NETWORK_LIMITED
public CellularNetwork register(Subscriber subscriber) throws java.io.IOException
getAvailableNetworks
.
Invoking register(Subscriber) 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.
Registrations of more than one subscriber to a cellular network may be supported by the network type and device. Different CellularNetwork instances are required for each subscriber.
When and if registration is successful a CellularNetworkListener.NETWORK_CONNECTED
event will be delivered to the listeners.
The javax.microedition.io.NetworkInterface
associated with the
registered CellularNetwork is available from getNetworkInterface()
.
The NetworkInterface is used to connect an AccessPoint
to the CellularNetwork.
subscriber
- the Subscriber to register;
if subscriber
is null
then automatic registration
mode is enabledthis
is returned if the CellularNetwork is registered using the subscriber;
otherwise it MUST be different than this
if the CellularNetwork
is already registered to a different subscriber and
multiple subscribers per network are supportedjava.io.IOException
- if the registration does not succeed.java.lang.UnsupportedOperationException
- if subscriber
is not null
and
if this CellularNetwork is registered to a different Subscriber and
registering the subscriber
to the same CellularNetwork is not supportedjava.lang.SecurityException
- if the CellularPermission for "networks" is not grantedgetRegisteredNetworks()
public 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.
At the time each listener is notified, the getSubscriber()
method must return the subscriber. The subscriber must be avilable to
the listener for both explicit amd implicit de-registrations.
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 javax.microedition.io.NetworkInterface getNetworkInterface()
NetworkInterface
connecting this CellularNetwork.NetworkInterface
if this CellularNetwork is registered;
otherwise null
is returnedNetworkInterface
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 getType()
"3GPP"
and "CDMA"
.
Additional network types may be provided by the implementation.
Refer to the CellularNetwork Property 'protocol'
for more detail on the link protocol.null
and not emptypublic 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 from 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 getType()
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 getType()
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) 2014, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.