Fields Summary |
---|
private static final String | TAG |
private android.content.Context | mContext |
private ITelephonyRegistry | mRegistry |
private static TelephonyManager | sInstance |
public static final String | ACTION_PHONE_STATE_CHANGEDBroadcast intent action indicating that the call state (cellular)
on the device has changed.
The {@link #EXTRA_STATE} extra indicates the new call state.
If the new state is RINGING, a second extra
{@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
a String.
Requires the READ_PHONE_STATE permission.
This was a {@link android.content.Context#sendStickyBroadcast sticky}
broadcast in version 1.0, but it is no longer sticky.
Instead, use {@link #getCallState} to synchronously query the current call state. |
public static final String | EXTRA_STATEThe lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
for a String containing the new call state. |
public static final String | EXTRA_STATE_IDLEValue used with {@link #EXTRA_STATE} corresponding to
{@link #CALL_STATE_IDLE}. |
public static final String | EXTRA_STATE_RINGINGValue used with {@link #EXTRA_STATE} corresponding to
{@link #CALL_STATE_RINGING}. |
public static final String | EXTRA_STATE_OFFHOOKValue used with {@link #EXTRA_STATE} corresponding to
{@link #CALL_STATE_OFFHOOK}. |
public static final String | EXTRA_INCOMING_NUMBERThe lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
for a String containing the incoming phone number.
Only valid when the new call state is RINGING.
Retrieve with
{@link android.content.Intent#getStringExtra(String)}. |
public static final int | PHONE_TYPE_NONENo phone module |
public static final int | PHONE_TYPE_GSMGSM phone |
public static final int | NETWORK_TYPE_UNKNOWNNetwork type is unknown |
public static final int | NETWORK_TYPE_GPRSCurrent network is GPRS |
public static final int | NETWORK_TYPE_EDGECurrent network is EDGE |
public static final int | NETWORK_TYPE_UMTSCurrent network is UMTS |
public static final int | SIM_STATE_UNKNOWNSIM card state: Unknown. Signifies that the SIM is in transition
between states. For example, when the user inputs the SIM pin
under PIN_REQUIRED state, a query for sim status returns
this state before turning to SIM_STATE_READY. |
public static final int | SIM_STATE_ABSENTSIM card state: no SIM card is available in the device |
public static final int | SIM_STATE_PIN_REQUIREDSIM card state: Locked: requires the user's SIM PIN to unlock |
public static final int | SIM_STATE_PUK_REQUIREDSIM card state: Locked: requires the user's SIM PUK to unlock |
public static final int | SIM_STATE_NETWORK_LOCKEDSIM card state: Locked: requries a network PIN to unlock |
public static final int | SIM_STATE_READYSIM card state: Ready |
public static final int | CALL_STATE_IDLEDevice call state: No activity. |
public static final int | CALL_STATE_RINGINGDevice call state: Ringing. A new call arrived and is
ringing or waiting. In the latter case, another call is
already active. |
public static final int | CALL_STATE_OFFHOOKDevice call state: Off-hook. At least one call exists
that is dialing, active, or on hold, and no calls are ringing
or waiting. |
public static final int | DATA_ACTIVITY_NONEData connection activity: No traffic. |
public static final int | DATA_ACTIVITY_INData connection activity: Currently receiving IP PPP traffic. |
public static final int | DATA_ACTIVITY_OUTData connection activity: Currently sending IP PPP traffic. |
public static final int | DATA_ACTIVITY_INOUTData connection activity: Currently both sending and receiving
IP PPP traffic. |
public static final int | DATA_DISCONNECTEDData connection state: Disconnected. IP traffic not available. |
public static final int | DATA_CONNECTINGData connection state: Currently setting up a data connection. |
public static final int | DATA_CONNECTEDData connection state: Connected. IP traffic should be available. |
public static final int | DATA_SUSPENDEDData connection state: Suspended. The connection is up, but IP
traffic is temporarily unavailable. For example, in a 2G network,
data activity may be suspended when a voice call arrives. |
Methods Summary |
---|
public void | disableLocationUpdates()Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged
PhoneStateListener.onCellLocationChanged} will be called on location updates.
Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
CONTROL_LOCATION_UPDATES}
try {
getITelephony().disableLocationUpdates();
} catch (RemoteException ex) {
}
|
public void | enableLocationUpdates()Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged
PhoneStateListener.onCellLocationChanged} will be called on location updates.
Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
CONTROL_LOCATION_UPDATES}
try {
getITelephony().enableLocationUpdates();
} catch (RemoteException ex) {
}
|
public int | getCallState()Returns a constant indicating the call state (cellular) on the device.
try {
return getITelephony().getCallState();
} catch (RemoteException ex) {
// the phone process is restarting.
return CALL_STATE_IDLE;
}
|
public CellLocation | getCellLocation()Returns the current location of the device.
Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION
ACCESS_COARSE_LOCATION}.
try {
Bundle bundle = getITelephony().getCellLocation();
return CellLocation.newFromBundle(bundle);
} catch (RemoteException ex) {
}
return null;
|
public int | getDataActivity()Returns a constant indicating the type of activity on a data connection
(cellular).
try {
return getITelephony().getDataActivity();
} catch (RemoteException ex) {
// the phone process is restarting.
return DATA_ACTIVITY_NONE;
}
|
public int | getDataState()Returns a constant indicating the current data connection state
(cellular).
try {
return getITelephony().getDataState();
} catch (RemoteException ex) {
// the phone process is restarting.
return DATA_DISCONNECTED;
}
|
public static android.telephony.TelephonyManager | getDefault()
return sInstance;
|
public java.lang.String | getDeviceId()Returns the unique device ID, for example,the IMEI for GSM
phones.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getDeviceId();
} catch (RemoteException ex) {
}
return null;
|
public java.lang.String | getDeviceSoftwareVersion()Returns the software version number for the device, for example,
the IMEI/SV for GSM phones.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
//
//
// Device Info
//
//
try {
return getSubscriberInfo().getDeviceSvn();
} catch (RemoteException ex) {
}
return null;
|
private ITelephony | getITelephony()
return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
|
public java.lang.String | getLine1AlphaTag()Returns the alphabetic identifier associated with the line 1 number.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getLine1AlphaTag();
} catch (RemoteException ex) {
}
return null;
|
public java.lang.String | getLine1Number()Returns the phone number string for line 1, for example, the MSISDN
for a GSM phone.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getLine1Number();
} catch (RemoteException ex) {
}
return null;
|
public java.util.List | getNeighboringCellInfo()Returns the neighboring cell information of the device.
try {
return getITelephony().getNeighboringCellInfo();
} catch (RemoteException ex) {
}
return null;
|
public java.lang.String | getNetworkCountryIso()Returns the ISO country code equivilent of the current registered
operator's MCC (Mobile Country Code).
Availability: Only when user is registered to a network
return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
|
public java.lang.String | getNetworkOperator()Returns the numeric name (MCC+MNC) of current registered operator.
Availability: Only when user is registered to a network
return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
|
public java.lang.String | getNetworkOperatorName()Returns the alphabetic name of current registered operator.
Availability: Only when user is registered to a network
return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
|
public int | getNetworkType()Returns a constant indicating the radio technology (network type)
currently in use on the device.
String prop = SystemProperties.get(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE);
if ("GPRS".equals(prop)) {
return NETWORK_TYPE_GPRS;
}
else if ("EDGE".equals(prop)) {
return NETWORK_TYPE_EDGE;
}
else if ("UMTS".equals(prop)) {
return NETWORK_TYPE_UMTS;
}
else {
return NETWORK_TYPE_UNKNOWN;
}
|
public java.lang.String | getNetworkTypeName()Returns a string representation of the radio technology (network type)
currently in use on the device.
switch (getNetworkType()) {
case NETWORK_TYPE_GPRS:
return "GPRS";
case NETWORK_TYPE_EDGE:
return "EDGE";
case NETWORK_TYPE_UMTS:
return "UMTS";
default:
return "UNKNOWN";
}
|
public int | getPhoneType()Returns a constant indicating the device phone type.
// in the future, we should really check this
return PHONE_TYPE_GSM;
|
public java.lang.String | getSimCountryIso()Returns the ISO country code equivalent for the SIM provider's country code.
return SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_ISO_COUNTRY);
|
public java.lang.String | getSimOperator()Returns the MCC+MNC (mobile country code + mobile network code) of the
provider of the SIM. 5 or 6 decimal digits.
Availability: SIM state must be {@link #SIM_STATE_READY}
return SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_NUMERIC);
|
public java.lang.String | getSimOperatorName()Returns the Service Provider Name (SPN).
Availability: SIM state must be {@link #SIM_STATE_READY}
return SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_ALPHA);
|
public java.lang.String | getSimSerialNumber()Returns the serial number of the SIM, if applicable.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getSimSerialNumber();
} catch (RemoteException ex) {
}
return null;
|
public int | getSimState()Returns a constant indicating the state of the
device SIM card.
String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
if ("ABSENT".equals(prop)) {
return SIM_STATE_ABSENT;
}
else if ("PIN_REQUIRED".equals(prop)) {
return SIM_STATE_PIN_REQUIRED;
}
else if ("PUK_REQUIRED".equals(prop)) {
return SIM_STATE_PUK_REQUIRED;
}
else if ("NETWORK_LOCKED".equals(prop)) {
return SIM_STATE_NETWORK_LOCKED;
}
else if ("READY".equals(prop)) {
return SIM_STATE_READY;
}
else {
return SIM_STATE_UNKNOWN;
}
|
public java.lang.String | getSubscriberId()Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getSubscriberId();
} catch (RemoteException ex) {
}
return null;
|
private IPhoneSubInfo | getSubscriberInfo()
// get it each time because that process crashes a lot
return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
|
public java.lang.String | getVoiceMailAlphaTag()Retrieves the alphabetic identifier associated with the voice
mail number.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getVoiceMailAlphaTag();
} catch (RemoteException ex) {
}
return null;
|
public java.lang.String | getVoiceMailNumber()Returns the voice mail number.
Requires Permission:
{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
try {
return getSubscriberInfo().getVoiceMailNumber();
} catch (RemoteException ex) {
}
return null;
|
public boolean | isNetworkRoaming()Returns true if the device is considered roaming on the current
network, for GSM purposes.
Availability: Only when user registered to a network
return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
|
public void | listen(PhoneStateListener listener, int events)Registers a listener object to receive notification of changes
in specified telephony states.
To register a listener, pass a {@link PhoneStateListener}
and specify at least one telephony state of interest in
the events argument.
At registration, and when a specified telephony state
changes, the telephony manager invokes the appropriate
callback method on the listener object and passes the
current (udpated) values.
To unregister a listener, pass the listener object and set the
events argument to
{@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
try {
Boolean notifyNow = (getITelephony() != null);
mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
} catch (RemoteException ex) {
// system process dead
}
|