KK_07k11A0585
KK_07k11A0585

Reputation: 2403

Android device telephone number

I am using the below method to get the phone number of my device



    private void getMyNumber()
            { 

        // read_phone_State permission is specified
            String ph_num ="";
            TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); 
                    ph_num = telephonyManager.getLine1Number(); // returning null 
                    ph_num = telephonyManager.getSimSerialNumber(); // returning sim serial number
                    ph_num = telephonyManager.getSubscriberId(); // returning id 
                    ph_num = telephonyManager.getVoiceMailNumber(); // returning null
            }

Any ideas ... how to get the phone number

Upvotes: 1

Views: 515

Answers (1)

Chris
Chris

Reputation: 23171

There is no 100% reliable way to get the phone number since whether or not the telephonyManager has access to it is dependent on the provider and how they encode the data on the SIM (for GSM phones, at least). If you want the phone number to uniquely identify the phone, use telephonyManager.getDeviceId() otherwise you may have to prompt the user for it.

Upvotes: 1

Related Questions