Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Getting Phone Details.Back to Android Cookbook Home | Up to Chapter: Telephone Applications

Author: Rachee Singh ('racheesingh')
In Published Edition? No
FormatLanguage: WikiFormat

Getting Phone Details.


Some Android applications require the Android device's IMEI number, the phone number or the phone type (GSM/CDMA).


We use an instance of the TelephonyManager class to obtain these details.


We obtain an instance of the TelephoneManager class to gain access to telephony related information:

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

To get the IMEI number, the phone type and the phone number we use inbuilt functions and set the appropriate text to the TextViews defined in the sample app.

        String IMEI = telephonyManager.getDeviceId();
        imei.setText("IMEI Number: "+ IMEI);
        int phoneType = telephonyManager.getPhoneType();
        if(phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
        	type.setText("Phone Type: CDMA");
        } else if(phoneType == TelephonyManager.PHONE_TYPE_GSM){
        	type.setText("Phone Type: GSM");
        String phoneNo = telephonyManager.getLine1Number();

        phoneNumber.setText("Phone Number: "+phoneNo);

See Also