Telephony In Android
Telephony Manager
Telephony Manager provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information. Applications can also register a listener to receive notification of telephony state changes.You do not instantiate this class directly; instead, you retrieve a reference to an instance through Context.getSystemService(Context.TELEPHONY_SERVICE).
Some More Good Android Topics
Customizing Toast In Android
Showing Toast for Longer Time
Customizing Checkboxes In Android
Customizing Progress Bar
Permission Required:
To work with Telephony Manager and to read the phone details we need
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> permission.So add this permission in your manifest file.
Accessing the Telephony Manager:
Have an object of TelephonyMnager
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
Get IMEI Number of Phone
String IMEINumber=tm.getDeviceId();
Get Subscriber ID
String subscriberID=tm.getDeviceId();
Get SIM Serial Number
String SIMSerialNumber=tm.getSimSerialNumber();
Get Network Country ISO Code
String networkCountryISO=tm.getNetworkCountryIso();
Get SIM Country ISO Code
String SIMCountryISO=tm.getSimCountryIso();
Get the device software version
String softwareVersion=tm.getDeviceSoftwareVersion()
Get the Voice mail number
String voiceMailNumber=tm.getVoiceMailNumber();
Get the Phone Type CDMA/GSM/NONE
/ /Get the type of network you are connected with
int phoneType=tm.getPhoneType();
switch (phoneType)
{
case (TelephonyManager.PHONE_TYPE_CDMA):
// your code
break;
case (TelephonyManager.PHONE_TYPE_GSM)
// your code
break;
case (TelephonyManager.PHONE_TYPE_NONE):
// your code
break;
}
Find whether the Phone is in Roaming, returns true if in roaming
boolean isRoaming=tm.isNetworkRoaming();
if(isRoaming)
phoneDetails+="\nIs In Roaming : "+"YES";
else
phoneDetails+="\nIs In Roaming : "+"NO";
if(isRoaming)
phoneDetails+="\nIs In Roaming : "+"YES";
else
phoneDetails+="\nIs In Roaming : "+"NO";
Get the SIM state/Details
int SIMState=tm.getSimState();switch(SIMState)
{
case TelephonyManager.SIM_STATE_ABSENT :
// your code
break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED :
// your code
break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED :
// your code
break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED :
// your code
break;
case TelephonyManager.SIM_STATE_READY :
// your code
break;
case TelephonyManager.SIM_STATE_UNKNOWN :
// your code
break;
}
How to Get IMEI number of the Phone
Getting Network Details
// Get connected network country ISO code
String networkCountry = telephonyManager.getNetworkCountryIso();
// Get the connected network operator ID (MCC + MNC)
String networkOperatorId = telephonyManager.getNetworkOperator();
// Get the connected network operator name
String networkName = telephonyManager.getNetworkOperatorName();
// Get the type of network you are connected with
int networkType = telephonyManager.getNetworkType();
switch (networkType) {
case (TelephonyManager.NETWORK_TYPE_1xRTT) :" Your Code ":
break;
case (TelephonyManager.NETWORK_TYPE_CDMA) :" Your Code ":
break;
case (TelephonyManager.NETWORK_TYPE_EDGE) : " Your Code ":
break;
case (TelephonyManager.NETWORK_TYPE_EVDO_0) :" Your Code ":
break;
Getting SIM Details :
Using the Object of Telephony Manager class we can get the details like SIM Serial number, Country Code, Network Provider code and other Details.
int simState = telephonyManager.getSimState();
switch (simState)
{
case (TelephonyManager.SIM_STATE_ABSENT): break;
case (TelephonyManager.SIM_STATE_NETWORK_LOCKED): break;
case (TelephonyManager.SIM_STATE_PIN_REQUIRED): break;
case (TelephonyManager.SIM_STATE_PUK_REQUIRED): break;
case (TelephonyManager.SIM_STATE_UNKNOWN): break;
case (TelephonyManager.SIM_STATE_READY):
{
// Get the SIM country ISO code
String simCountry = telephonyManager.getSimCountryIso();
// Get the operator code of the active SIM (MCC + MNC)
String simOperatorCode = telephonyManager.getSimOperator();
// Get the name of the SIM operator
String simOperatorName = telephonyManager.getSimOperatorName();
// -- Requires READ_PHONE_STATE uses-permission --
// Get the SIM’s serial number
String simSerial = telephonyManager.getSimSerialNumber();
}
}
No comments :
Post a Comment