How can I programmatically get the phone number of the device that is running my android app?
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.
Dial a Code 1. Dial 99 or *#99# on your phone. 2. Your phone number will be displayed on the screen.
Code:
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number();
Required Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With