0

How to get the phone number from an android phone. I have used this code but it doesn't get the current number. It get the number that came with the phone, so if I change the SIM it gets the previous number.

    TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String number = manager.getLine1Number();

This code gets a number but not the the current one. How would I get the current number.

Declan Marks
  • 65
  • 1
  • 8

2 Answers2

0

try using this

TelephonyManager telemamanger = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();  

and use:

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

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"/>

Note : it is only possible in single sim phone , if you try with dual sim phone then you not getting your phone number.

TopsAndy
  • 202
  • 2
  • 11
  • I might also check to see if they have set it in the 'Me' contact. How to I access the Me contact and get the number – Declan Marks Jul 13 '17 at 10:47
  • @DeclanMarks This link may be helpful to you. https://developer.android.com/training/contacts-provider/retrieve-names.html and https://stackoverflow.com/a/40866451/5742249 – TopsAndy Jul 14 '17 at 13:03