Breaking News


Wednesday 15 January 2014

TELEPHONE IN ANDROID

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";

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;


                                              Android Telephony


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();

          }
}
Share This
Blogger
Facebook
Disqus

comments powered by Disqus

No comments :

Post a Comment

Subscribe
Labels
Popular Posts

Subscribe Via Email

About Us

THIS IS ANDROID AND JAVA FREE TUTORIAL AND ALL PROVIDE SOLUTION IN ANDROID AND JAVA INTERVIEW QUE AND ANS IS AVAILABLE IN MY BLOG AND ANY QUERY PLEASE CONTACT ME GO NOW CONTACT US PAGE.

Total Pageviews

© Android and Java solution All rights reserved | Designed By Fireandroids