Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically obtain the phone number of the Android phone

How can I programmatically get the phone number of the device that is running my android app?

like image 411
jkap Avatar asked Mar 19 '10 20:03

jkap


People also ask

How can I know my sim card number in Android programmatically?

You can try this for get sim serial number and get sim number and Don't forget to add permission in manifest file. TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context. TELEPHONY_SERVICE); String getSimSerialNumber = telemamanger. getSimSerialNumber(); String getSimNumber = telemamanger.

How do I find the code for my Android Phone?

Dial a Code 1. Dial 99 or *#99# on your phone. 2. Your phone number will be displayed on the screen.


1 Answers

Code:

TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number(); 

Required Permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>  

Caveats:

According to the highly upvoted comments, there are a few caveats to be aware of. This can return null or "" or even "???????", and it can return a stale phone number that is no longer valid. If you want something that uniquely identifies the device, you should use getDeviceId() instead.

like image 145
Alex Volovoy Avatar answered Nov 19 '22 22:11

Alex Volovoy