Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the mobile number of current sim card in real device?

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?

like image 977
Narasimha Avatar asked Feb 05 '10 10:02

Narasimha


People also ask

Is the SIM card number on the actual SIM card?

How do I find my SIM card number? Your SIM card number (also called ICCID) is normally printed on your SIM card and/or your SIM card packaging, it is always a good idea to keep your SIM card packaging in case you ever need to check your SIM card number at a later date.


2 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.)

like image 198
Dave Webb Avatar answered Sep 27 '22 17:09

Dave Webb


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; 
like image 21
Amarnath Baitha Avatar answered Sep 27 '22 17:09

Amarnath Baitha