0

How can I get the current phone number used in a device? I am testing in Marshmallow version Moto G3.

I have tried this with there permission. I have also requested them at runtime.

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

Here is my code.

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

But getLine2Number returns blank.

Evin1_
  • 12,292
  • 9
  • 45
  • 47
vivek jha
  • 9
  • 3
  • 2
    Possible duplicate of [Programmatically obtain the phone number of the Android phone](https://stackoverflow.com/questions/2480288/programmatically-obtain-the-phone-number-of-the-android-phone) – mrogers Jul 17 '17 at 15:43

1 Answers1

0

This is not solution, but pay attention to that you not always can get phone number. For example, I had some SIM card with my phone number. I went to the mobile operator service office and bought new micro SIM card with number saving. After this my phone doesn't recognize my phone number, because SIM card doesn't have this phone number. Now my phone number recognizes in network on mobile operator service level.

kostyabakay
  • 1,649
  • 2
  • 21
  • 32