I have to make an application which shows the contact no of the SIM card that is being used in the cell. For that I need to use TelephonyManager
class. Can I get details on its usage?

- 237,138
- 77
- 654
- 440

- 3,802
- 11
- 55
- 83
-
3You really should try to explain your question a lot better. Your question is hard to understand and lacks any details that would allow anyone to help you. – Donal Rafferty Feb 05 '10 at 10:52
-
Are you trying to get the mobile number of device in to your Android application? – slhsen Feb 05 '10 at 11:07
-
Hi Narasimha, I want 10 digit phone number, tm.getLine1Number() returns null. Can you please share your solution ? – Gangadhar Nimballi Mar 28 '14 at 10:27
-
Weird. When I click 'status' I get a different phone umber to my own one. I think this may be because I have been using the same mobile/ cell forever. But I have switched network provider. So the new network provider has done something like ported my number, which is 087, to their system, which is 085 prefix. The status on my phone says my phone number is 085 XXXXXX, but this number means nothing to me or anyone who knows me. – CHarris Jan 02 '15 at 22:34
6 Answers
You can use the TelephonyManager
to do this:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The documentation for getLine1Number()
says this method will return null
if the number is "unavailable", but it does not say when the number might be unavailable.
You'll need to give your application permission to make this query by adding the following to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
(You shouldn't use TelephonyManager.getDefault()
to get the TelephonyManager
as that is a private undocumented API call and may change in future.)

- 2,165
- 1
- 27
- 26

- 190,537
- 57
- 313
- 299
-
1
-
1in emulator its giving proper value.but in real device it returns null value.why?please can u give any solution for this – user1213202 Mar 27 '12 at 09:18
-
12Sometimes, the number is not burned on your sim card. You can check it by going to your settings, click About phone, check the phone number by clicking the status item. If your number is not shown, then the there is no way for you to get the number on your own application. – vida May 21 '13 at 03:17
-
-
It is returning null on my HTC AT&T device, How to get it, I am really need it. – Gangadhar Nimballi Mar 28 '14 at 10:25
-
i had added this permission READ_PHONE_STATE in .xml file, where should i keep this code "TelephonyManager tm" – Pratap Penmetsa Mar 04 '19 at 10:16
Hi Actually this is my same question but I didn't get anything.Now I got mobile number and his email-Id from particular Android real device(Android Mobile).Now a days 90% people using what's App application on Android Mobile.And now I am getting Mobile no and email-ID Through this What's app API.Its very simple to use see this below code.
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
for (Account ac : accounts)
{
acname = ac.name;
if (acname.startsWith("91")) {
mobile_no = acname;
}else if(acname.endsWith("@gmail.com")||acname.endsWith("@yahoo.com")||acname.endsWith("@hotmail.com")){
email = acname;
}
// Take your time to look at all available accounts
Log.i("Accounts : ", "Accounts : " + acname);
}
and import this API
import android.accounts.Account;
import android.accounts.AccountManager;

- 561
- 1
- 6
- 19
-
2
-
@Amarnath Baitha In WhatsApp U can use the any sim number witch one not inserted on this device where WhatsApp is installed?? that's time what is the right solution? It's never mandatory in What'SApp that simcard is require!! – Zala Janaksinh Oct 08 '14 at 08:49
I have to make an application which shows the Contact no of the SIM card that is being used in the cell. For that I need to use Telephony Manager class. Can i get details on its usage?
Yes, You have to use Telephony Manager;If at all you not found the contact no. of user; You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
Add permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
import android.telephony.TelephonyManager;
Use the below code:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();

- 71
- 12
Well, all could be temporary hacks, but there is no way to get mobile number of a user. It is against ethical policy.
For eg, one of the answers above suggests getting all accounts and extracting from there. And it doesn't work anymore! All of these are hacks only.
Only way to get user's mobile number is going through operator. If you have a tie-up with mobile operators like Aitel, Vodafone, etc, you can get user's mobile number in header of request from mobile handset when connected via mobile network internet.
Not sure if any manufacturer tie ups to get specific permissions can help - not explored this area, but nothing documented atleast.

- 124
- 10
Sometimes you can retreive the phonenumber with a USSD request to your operator. For example I can get my phonenumber by dialing *116# This can probably be done within an app, I guess, if the USSD responce somehow could be catched. Offcourse this is not a method I would recommend to use within an app that is to be distributed, the code may even differ between operators.

- 211
- 2
- 13
-
This is not working for all the operators in all the countries. – Vinothkumar Arputharaj Apr 10 '12 at 08:48
-
Thats correct, and thats also what I wrote in my comment "sometimes you can retreive the phonenumber ...". In some cases they might use a different USSD code and Sometimes they might not have the feature at all. – ziggestardust Apr 21 '12 at 14:29
-
USSD response can be retrieved using `AccessibilityService`. This works for most operators I think. But then, you would need to access Accessibility permission which is considered as dangerous permission. – cgb_pandey Mar 08 '23 at 11:23
As many said:
String phoneNumber = TelephonyManager.getDefault().getLine1Number();
The availability depends strictly on the carrier and the way the number is encoded on the SIM card. If it is hardcoded by the company that makes the SIMs or by the mobile carrier itself. This returns the same as in Settings->about phone.

- 455
- 4
- 11
-
8There's no `getDefault()` method in the `TelephonyManager` class. – Matthew Quiros Sep 04 '12 at 06:24
-
3@Matt There was when Android was still in beta, but you're right... when this question was asked (well after Android 1.0) it had been removed from the API. – Jeremy Logan Jan 09 '14 at 23:48