Reputation: 143
Suppose my phone no is 9-112-345-678, I try given code
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String phoneNo = mTelephonyMgr.getLine1Number();
but its not giving any output when i install same application in samsung fit 2.2.1 O.S.
I also gave necessary permission
uses-permission android:name="android.permission.READ_PHONE_STATE"
Upvotes: 1
Views: 1284
Reputation: 68177
It depends on SIM card. If your SIM card contains it, then getLine1Number would return you, otherwise its empty. You can verify this by going into:
Settings->About Phone->Status->My phone number
On the other hand, take any old nokia/sony-ericsson phone, put your sim in it, and browse to an option to Insert/Edit your sim number. I know, i had to do this to fix this issue with my phone number.
Upvotes: 1