I want to know user mobile number in Android. I used this code but I'm not getting number.
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String n = tm.getLine1Number();
Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Is it compulsory to save number in android mobile settings --> about phone --> status --> myphone number
Any idea on this?
Find My SIM Card Number on an AndroidGo to Settings > About Phone > Status, then scroll down and locate the ICCID (SIM Card) number.
It's a unique 18-22 digit code that includes a SIM card's country, home network, and identification number. You'll usually find an ICCID printed on the back of a SIM card, but sometimes it's included in the packaging materials instead.
I think sim serial Number and sim number is unique. 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.getLine1Number();
And add below permission into your Androidmanifest.xml
file.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Let me know if there is any issue.
Getting the Phone Number, IMEI, and SIM Card ID
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
For SIM card, use the getSimSerialNumber()
//---get the SIM card ID--- String simID = tm.getSimSerialNumber(); if (simID != null) Toast.makeText(this, "SIM card ID: " + simID, Toast.LENGTH_LONG).show();
Phone number of your phone, use the getLine1Number() (some device's dont return the phone number)
//---get the phone number--- String telNumber = tm.getLine1Number(); if (telNumber != null) Toast.makeText(this, "Phone number: " + telNumber, Toast.LENGTH_LONG).show();
IMEI number of the phone, use the getDeviceId()
//---get the IMEI number--- String IMEI = tm.getDeviceId(); if (IMEI != null) Toast.makeText(this, "IMEI number: " + IMEI, Toast.LENGTH_LONG).show();
Permissions needed
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
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