Get phonenumber programmatically - Android

JavaForAndroid picture JavaForAndroid · Jun 25, 2013 · Viewed 33.3k times · Source

is it possible to get the phonenumber of each device programmatically? I tried this code:

TelephonyManager manager =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
mPhoneNumber = manager.getLine1Number();

This works fine with some providers. Unfortunately it does not work with each provider. So i am looking for a trick or work around to get the phonenumber of the device. Is there a solution or is it impossible because the number is not stored on the sim card?

Answer

Raghav Sood picture Raghav Sood · Jun 25, 2013

The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do. For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.