9

I tried googling in google but unable to find the answer

Will anyone please let me know, how can i retrieve the current phone number from the android code. I think phone number will be stored in the sim card.

Thanks & Regards, SSuman185

Suman
  • 4,221
  • 7
  • 44
  • 64
  • this is the link may be useful to u http://mobile.tutsplus.com/tutorials/android/android-essentials-using-the-contact-picker/ – Parag Chauhan Feb 08 '11 at 07:07

2 Answers2

22

You can try:

TelephonyManager phoneManager = (TelephonyManager) 
    getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();

Needs READ_PHONE_STATE permission.

Sebastian Roth
  • 11,344
  • 14
  • 61
  • 110
  • Hi Sebastian, I am sorry actually it was returning some number i thought it will be the phone number and when i printed i came to know that it is only 2 digit, but actually phone number is 10 digit right. Please help me if u know how to get the 10 digit phone number – Suman Feb 10 '11 at 06:07
  • 3
    Doesn't work for me either (Android 2.1 and 2.2 with provider Telstra). In my case it always returns empty. Also Android itself in "About Phone" has number as empty. – Carsten May 11 '11 at 03:20
  • 3
    There is no reliable method to get the phone number of the device. – David Wasser Jul 02 '12 at 16:49
  • 1
    It doesn't work for me,am using android 4.4, Please let me know, Is there any way to find this? – Vipin Nov 08 '14 at 14:28
0
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String phonenumber = tm.getLine1Number();

This link may be the best collection of TelephonyManager related answers. But still it is not guaranteed that you will be returned a telephone number.

Check this out!

Community
  • 1
  • 1
gurkan
  • 3,457
  • 4
  • 25
  • 38