Get My Phone Number

1 vote · 2 comments

Gets the phone number the app is running on. It needs a permission so add the line uses-permission android:name="android.permission.READ_PHONE_STATE" to the manifest.xml

raw ·
copy
· download
private String getMyPhoneNumber(){ TelephonyManager mTelephonyMgr; mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return mTelephonyMgr.getLine1Number(); } private String getMy10DigitPhoneNumber(){ String s = getMyPhoneNumber(); return s.substring(2); }
Add a comment

2 Comments

Not allways working

Reply · April 24, 2011, 2:39 a.m.

Number that we use here is 10 digits long and i get only 8 ! Anyone a solution for this ?

Reply · April 25, 2011, 4:47 a.m.